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.

Hi Paul
Just an update: we figured out that the error message was generated only due to a memory issue due to our large data set - there was nothing wrong with the model specifications. I spent quite alot of time trying to figure out why the function would not work for my model due to the wording of the error message, but it turned out to be as simple as using the nsample-argument to use a fraction of the model sample in the estimations. So I am wondering whether it would be helpful to omit this error message in cases where it is only memory issues that hinder the function to run properly? Best, Tiril

Yeah, I guess my “replacing” of error messages didn’t went well in the situation. Let me try to improve that.

A follow-up question: Did you also see the original error mesage in addition to the “something went wrong…” one?

Yes I got both messages.