Serial medition with 2 mediators using brms

I want to implement a serial mediation with 2 mediators using brms. I set up the following model:

model_mediator1 <- bf(M1 ~ X)
model_mediator2 <- bf(M2 ~ X + M1)
model_outcome  <- bf(Y ~ X + M1 + M2)

med_result = brm(
  model_mediator1 + model_mediator2 + model_outcome + set_rescor(FALSE), 
  data = da1, 
  cores = 4

Does this implementation reflect Process Model 6 with 2 mediators?

Yes, your model code looks good, to me. For more on how to fit Hayes-style models with brms, you might check out this ebook.


This seems like a great project

The syntax looks fine, I would recommend for the next step to use the hypothesis() function from brms to test the indirect effects etc, like

hypothesis(med_result, "M1_X * M2_M1 * Y_M2 > 0")

Also, if you want to run this types of models from the SEM framework you can use the blavaan package which also uses Stan for Bayesian SEM. For your model would look like this


mod_med <- '
Y ~ cp*X + b1*M1 + b2*M2
M1 ~ a1*X
M2 ~ a2*X + d21*M1

## indirect
ind1 := a1*d21*b2
ind2 := a1*b1
ind3 := a2*b2
ind4 := d21*b2

fit_med <- bsem(mod_med, data=dat, fixed.x=F)
summary(fit_med, standardize=T, rsquare=T)

1 Like

Thank you, I checked your ebook and it’s very helpful! One question that came up to me was if I always have to add an intercept to the mediation models?

Very useful, I will use this for some robustness checks. Thank you!

I’m not aware that you can decide to omit the mean structure with brms the way you would with SEM software. So to my knowledge, yes, the intercept is always a part of the model.

You can omit the intercept for each path with bf(y ~ 0 + x), does that work?

I am pretty sure can omit the intercept in brms, with either 0 or -1 in the bf. But to clarify you wouldnt be excluding the intercept from the model, you would be fixing it to 0. Which sounds weird to me for a mediation model, unless you have standardized all the variables before.

This does differ on the use of the intercepts in SEM, in frequentist SEM the intercepts are not included by default, but in that case it does not mean that they are fix to 0. This because the relations between variables are evaluated based on the covariance matrix, so the means/intercepts can be excluded without adding extra constraints. Now, BSEM models in blavaan will always include the means/intercepts and you would have to fix them to 0 if that is what you are looking for

1 Like


I was not aware that the intercept is automatically entering the equations the way I wrote the model for brms. I think there is no need to set them to 0 in my case, so I will leave it as it is.

Thanks for the great support!

The DAG figures look really nice! What software did you use to make them?

I did not make them. I got them from following source, page 9: Figures

Yeah, when you think of mediation models with the aid of path models like AF Hayes uses in his books, it’s easy to forget about the intercepts. But if you use his PROCESS macros, you’ll discover they’re still there, lurking in the shadows. And to be fair to Hayes, he discussed intercepts in his textbooks. Anyway, unless you have strong reasons to do otherwise, I recommend including the intercepts in your models and thinking carefully about how they might influence the other parameters.

1 Like