Me() wrapped inside bs() breaks

Here is a model that I’m trying to run. I’m trying to add an error term in the predictor variable x. The error is Gaussian with mean mu_x and sd sdx. I’m using me() to do this.

m2.1<- brm(y ~ bs(me(mu_x,sdx), df=3, degree = 3) + (1|site),
family = poisson(),
data = d,
prior = c(set_prior(“normal(2, 0.5)”, class = “Intercept”),
set_prior(“normal(-0.2, 0.1)”, class = “b”)),
save_pars = save_pars(all = TRUE))

Here is the error:

Compiling Stan program…
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
Syntax error in ‘string’, line 52, column 44 to column 45, parsing error:
Ill-formed expression. Found identifier. There are many ways to complete this to a well-formed expression.

I understand that me() is soft deprecated, and that mi() is preferred, but I’m not clear how to use mi() to model this kind of measurement errors in the data. Or it could simply be that bs() doesn’t handle measurement error in the predictors?

Thank you!

me() does unfortunately not work if wrapped in non-elementary functions such as bs(). Neither would mi(). The reason is that me() and mi() terms are evaluated inside Stan while bs() would try to prepare spline basis functions inside of R before passing them to Stan.

1 Like