Random slopes with posterior_linpred


#1

Hello,

I am trying to use the posterior_linpred function in brms to get predictions across one grouping variable, which has random intercepts and random slopes, while marginalizing over (excluding) the random effects of other grouping variables. I understand that I need to use the re_formula argument to accomplish this, but I have a question about the proper syntax.

In a model with both random intercepts and random slopes, does re_formula = ~ (1|group) include all random effects, or just the intercept? If I try re_formula = ~ (1 + slope|group) I get an error for repeating a group in the re formula.

Thanks,
Erik


#2

If you write re_formula = ~ (1|group) you include just the intercept.

The error when using re_formula = ~ (1 + slope|group) seems strange to me. Do you have a minimal reproducible example for me to try out?


#3

Hi Paul,

I sorted this out. The error had to do with the imputation structure. ~ (1 + mi(x)|group) causes the problem. Switching to just ~ (1 + x|group) cleared it up.

Thanks,
Erik


#4

Was that a mistake from your side of did anything not work in the expected way (i.e. is there something I need to fix)?


#5

That was just me not knowing how to specify predictions with an imputed predictor.