How to execute Two-Group Moderated Multilevel Mediation in brms (1-1-1 with level 1 moderator)?

Hello:

I have four variables that are all level 1 variables in a multilevel model. I am trying to execute moderated multilevel mediation in R, using the brms package. The moderator (Mod) is a categorical two-level variable at level 1. All three of the other variables (Pred, Med, and Resp) are continuous.

I have been trying to write it but I don’t think I am doing it correctly. Can someone help explain how to effectively write a two-group moderated multilevel mediation in brms?

Among the things I am confused about:

  • When to use bf() versus brm() and why sometimes people have bf() inside of brms()
  • Why some versions I have seen of doing mediation in brms use set_rescor(FALSE)

I have found this page and this page that seem to have accurate descriptions for how to do mediation and multilevel mediation in brms but I wasn’t sure about two group moderated multilevel mediation in brms.

Right now I have:
brm_M_0 <- brm(Resp ~ Pred + (Pred | subID), medDf, family = gaussian())
summary(brm_M_0)
brm_M_M <- brm(Med ~ Resp + (Resp | subID), medDf, family = gaussian())
summary(brm_M_M)
brm_M_Y <- brm(Resp ~ Pred + Med + (Pred + Med | subID), medDf, family = gaussian())
summary(brm_M_Y)

But how do I incorporate a categorical two-level moderator into this? And how do I make it into a moderated multilevel mediation? I’m pretty stumped. Thank you so much for any help!

Hi,
sorry to hear you are having problems. Please use the “Interfaces - brms” category for brms related questions otherwise they will likely remain overlooked.

I unfortunately don’t understand mediation models, but maybe @Guido_Biele is not busy and can help?

Here are a few quick hints:

brm will estimate a Bayesian model. The first object in brm is always one or more model-equations. It is here that bf comes into play, because you can use is to submit multiple model-equation to one Bayesian model you want to estimate in brms.

This is relevant for mediation analysis, because it consists of an outcome-model and a mediator-model that are simultaneously estimated in one Bayesian model. The code you described above does not do this, and thus you can’t use the later steps of the approach described by Mathew Clark.

Setting res_cor = F is, as far as I know, often motivated by having a simpler model, because estimating the correlation between the residuals of the two models will make the model fitting process slower.

It appears to me that at the moment the main challenge for your analysis is not the multilevel part, but just getting a basic mediation analysis going. I think this is well described in Mathew Clarks example, and following steps could bring you to your goal: (1) replicate the example Mathew Clark did (2), set up a simple mediation model with you own data (no-multilevel), (3) Expand this simple model to the more complex multilevel structure you want to achieve.

1 Like