Last active
July 26, 2018 12:55
-
-
Save padpadpadpad/c81b97de597e9b7ac9a9e71a33e118a5 to your computer and use it in GitHub Desktop.
script to run a breakpoint analysis where the second slope is constrained to 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # want to model the data as a segmented regression, so the curve has two straight lines, segmented regression can do this | |
| # xChange is the x value at which the gradients change when the gradient after xChange is forced to be 0 | |
| lin_segment <- function(a, x, xChange, c){ | |
| lin.segment <- a*(abs(x - xChange) - (x + xChange)) + c | |
| return(lin.segment) | |
| } | |
| x <- 1:100 | |
| plot(lin_segment(-10, x, 20, 0) ~ x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment