Errors with BLUPs with complex random effects in brms using posterior_epred

Hi all,

I’ve fit a mixed effects model to some looking-time data from several experiments, and now I’d like to extract a BLUP for the effect of Condition in each subject. The model code looks like this:

SmallerLT ~ Condition*scale(TrialNumber)+(1+Condition*scale(TrialNumber)|Study/CID)

I created a dataframe with one row for each subject and study, and passed this as newdata to a call like this:

t <- posterior_epred(b_1, newdata = newdat, scale = "linear", re_formula = ~ (1|Study/CID)) %>% 

However, I’m getting errors like the following:

“Error: The following variables can neither be found in ‘data’ nor in ‘data2’:

If I pass the entire original dataframe, with a unique value of Study, CID, Condition, and Trial for each row, I do get back samples, but I’m not sure how to collapse across all these dimensions manually in a statistically responsible way to find one summary statistic for each subject’s (CID) value of Condition (abstracting away from TrialNumber, and taking into account the Study (which is what I had hoped to extract from the model). Any suggestions on this front would be greatly appreciated!


One solution would be to use a reference value for TrialNumber, like the grand mean or some other sensible value.

1 Like

That’s a good idea - tried it and it yielded sensible results. Thanks a lot!

1 Like