Skip to main content
2 of 2
replaced http://stats.stackexchange.com/ with https://stats.stackexchange.com/

Model broken stick model in R where one line has a constant gradient?

I am current using the package (lme4) for a mixed effect model with random effects.

My model takes the form:

mod <- lmer(response ~ b1(predict1, bp) + b2(predict2, bp) + (1 | site), data = data)

The functions b1 and b2 come from the helpful advice in:

Estimating the break point in a broken stick / piecewise linear model with random effects in R [code and output included]

b1 <- function(x, bp) ifelse(x < bp, bp - x, 0)
b2 <- function(x, bp) ifelse(x < bp, 0, x - bp)

I am wondering, how would I set up my model so that the second part (line) of the broken stick model has a constant gradient?

So for example, I would like something like:

If X < breakpoint, Y = m1X + C1

If X > breakpoint, Y = C2

Hope I am making sense.

Matt.

mjburns
  • 1.1k
  • 3
  • 13
  • 16