Skip to content

Instantly share code, notes, and snippets.

@padpadpadpad
Last active July 26, 2018 12:55
Show Gist options
  • Select an option

  • Save padpadpadpad/c81b97de597e9b7ac9a9e71a33e118a5 to your computer and use it in GitHub Desktop.

Select an option

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
# 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