Measurement error broken stick model in brms

I was wondering how to incorporate measurement error for a predictor in which I am also implementing a piecewise / broken-stick regression scheme. If I just fit a measurement error model for my predictor I could do it easily as

brm(Y ~ 1 + me(X, sd))

But I now want to fit a model with an upper threshold for X at which below this threshold the association between X and Y is zero, and above is nonzero. Since the threshold is known I want to fit it along the lines of

Y ~ 1 + (me(X, sd) - threshold) * I(me(X, sd) - threshold > 0)

I wassw ondering if this is possible in brms or if I should just switch to STAN and code this directly?

1 Like

Hi,
that seems like a hard model to fit in general and I would switch to pure Stan. It might be possible to hack this around in brms (because you can mix pure Stan into brms models if needed), but I think you’ll be getting disadvantages of brms without much advantages in this case.

The big problem is going to be that the model as you specified it makes the likelihood not smooth around the threshold which will pose problems for the sampler.

I see two general ways to address this:

  1. Use a smooth approximation to the threshold (e.g. log1p_exp a.k.a. “softplus”)
  2. Threat the “is true value of X below threshold” as a discrete variable to be marginalized out. The probability of being below threshold can be computed via normal_lcdf and then you will have a parameter with <lower=threshold> only for the case when true X is above threshold… Sorry if I am not being completely clear, I don’t think I have all the details of this figured out, but hope this guides you in the right direction.

Best of luck with your model!