Issues using posterior_predict function with weighted models


Please also provide the following information in addition to your question:

•Operating System: Windows 10
•brms Version: 2.2.0

Hi Paul
I have used the brm function to run hierarchical models and then used the posterior_predict function on the generated models without issues (details on how we have defined the model can be found here: Running time for hierarchical model ). However, I have now calculated the same models with the addition of using weights, using this formula in the brm function: yi | weights(wei) ~ predictors (i.e. the only change in the model formulae is the inclusion of the weights, all other arguments are identical to the unweighted models). When trying to use posterior_predict on the weighted models I am given the following error message: “Something went wrong. Did you transform numeric variables to factors or vice versa within the model formula? If yes, please convert your variables beforehand. Or did you set a predictor variable to NA? If no to both, this might be a bug. Please tell me about it.” I did not transform the variables and there are no NA’s in the data used.
Since the inclusion of weights is the only change in the weighted model I assume that this is what is causing trouble, but I cannot figure out how or why. Do you have any suggestions?
Thanks in advance for your reply.


Hi Tiril,

can you provide a minimal reproducible example? A basic weighted model does not create this issue (with the github version of brms):

df <- data.frame(y = rnorm(100), w = 1:10, x = rnorm(100))
fit <- brm(y | weights(w) ~ x, data = df)

Edit: Maybe you sould update brms to the latest CRAN version (2.4.0) and see if that solves your problem.


I am about to submit the next version of brms to CRAN, but I want to be sure that this issue is resolved before submitting. Could you please try out brms 2.4.0 from CRAN or 2.5.0 from github and if it still fails provide a reproducible example? That would help me a lot! :-)

Update: I did some tests and I can’t reproduce your error not even with brms 2.2.0. Is the weighting variable also used somewhere else in the model?


Sorry for being slow here (I am working with Tiril). We also could not reproduce the error with a different data set. So it looks that something went wrong with the particular dataset Tiril was working with.


Thanks for the quick response! Good to know it does not seem to be a general problem.