Multiple imputation and brms

412 views
Skip to first unread message

Michael Adkins

unread,
Mar 10, 2017, 10:40:35 AM3/10/17
to brms-users
Hello to all,

I'm currently fitting two-level hierarchical models of political party support using the British Election Study and I'm finding that a number of the covariates have missing values. For my final model, the missingness halves the sample size which is really problematic. I have produced several imputation models and fit them with the package Jomo in R and extracted several (now) complete datasets. If I fit this in Stan directly (by extracting the model code or writing it from scratch), I tend to run a complete dataset on each chain and mix the samples by merging the resulting stan objects, but I'm just wondering if there is an effective way to do this in brms without losing the convenient functions in the rest of the package - such as predict, marginal effects etc.

Thanks in advance and I hope that makes sense!

Kind regards,

Mike

Paul Buerkner

unread,
Mar 10, 2017, 10:49:24 AM3/10/17
to brms-users
If you already know how to "merge" stan objects, you should be able to do this in brms as well.

If you have a brmsfit object named, say, "model", you can extract the related stanfit object via model$fit and amend it, that is merge the Stan objects and put them back into one of the brmsfit objects.

With the exception of model$data and model$fit, the brmsfit object will be identical so merging the related stanfit objects should not break the post-processing methods you mentioned.
Keep in mind though that any method making use of the old data (such as predict when not using argument "newdata") will use the particular imputed data set of this brmsfit object.
marginal_effects, for instance, does not use the old data so that it will be unaffacted by the particular dataset.

Michael Adkins

unread,
Mar 11, 2017, 8:30:12 AM3/11/17
to brms-users
Brilliant! Really simple solution. Thank you!

Zachary Powell

unread,
Feb 5, 2018, 5:51:33 PM2/5/18
to brms-users
Hello all,

I'm in a similar situation and need to clarify something for my own education. Based on Michael's post, I'm guessing the solution is to estimate a brms model for each imputed data set, merge the models together, and then proceed with any other summary, predicted margins, etc?

For example:

a <- brms(...data = ImpData$imp1, seed = 903)
b <- brms(...data = ImpData$imp2, seed = 214)
c <- brms(...data = ImpData$imp3, seed = 972)


FullMods <- sflist2stanfit(c(a, b, c))

summary(FullMods)

Is this correct? Thank you for your help.

ZAP

Paul Buerkner

unread,
Feb 5, 2018, 5:54:07 PM2/5/18
to Zachary Powell, brms-users
There is already a built in solution for this in brms 2.1.0 (on CRAN). Try out

fit <- brm_multiple(..., data = ImpData)

where ImpData is a list of imputed data sets. The resulting fitted model object can be handled as any other model object of brms. See also ?brm_multiple

--
You received this message because you are subscribed to the Google Groups "brms-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+unsubscribe@googlegroups.com.
To post to this group, send email to brms-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brms-users/ab41c92e-721d-4c8d-97c6-6c9b9869ed8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zachary Powell

unread,
Feb 5, 2018, 8:28:07 PM2/5/18
to brms-users
Ah, I see. I should have checked for updates to your package. 

Thank you very much for your help. You have no idea how much trouble you've saved me.
To unsubscribe from this group and stop receiving emails from it, send an email to brms-users+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages