Mediation question using brms

  • Operating System: Mac OSX
  • brms Version: 2.30

I’m attempting to do a multilevel mediation analysis. The dv is a likert scale response which I am modeling with a cumulative distribution (logit link). The mediator is categorical (Yes / No). When calculating the ab path, I am wondering if I can multiply the a and b coefficients directly (as below).

Knowledge_Judgment_mod <- bf(KnowledgeResponse ~ Condition + CounterfactualResponse + (1|Subject), family = “cumulative”)

Counterfactual_mod <- bf(CounterfactualResponse ~ Condition + (1|Subject), family = “bernoulli”)

model1 <- brm(Knowledge_Judgment_mod +
Counterfactual_mod,
set_rescor(FALSE),
data=data1,
iter=3000,
warmup=1500,
control = list(adapt_delta = .90),
prior = c(set_prior(“normal(0,1)”, class = “b”)))

a <- posterior_samples(model1, pars = “CounterfactualResponse_ConditionSpecific”)
b <- posterior_samples(model1, pars = “KnowledgeResponse_CounterfactualResponse”)
a_b <- a*b

summary(a_b)

CI_Model1_Mediation <- quantile(a_b$b_CounterfactualResponse_ConditionSpecific, probs = c(.025,.975))

CI_Model1_Mediation

1 Like

That approach seems to be right from what I see.

Maybe this is of interest for you: I have drafted a function, mediation(), that prints a compact summary especially for mediation analysis (similar to the output from the mediation package).

You can see examples in a vignette here:
https://strengejacke.github.io/sjstats/articles/bayesian-statistics.html#summary-of-mediation-analysis

There’s a comparison of brms to the mediation package, and the results look good!

You need the current dev-version of sjstats to check out the mediation()-function.

3 Likes

I have a short follow-up question here -

If the mediator is normally distributed, and the outcome is negative binomial distributed, does taking the product of the coefficients still work for calculating the indirect effects? Thanks!

Don’t think so because different links but correct me if I’m wrong

1 Like

Ah, gotcha, so in your original example, it should work because the logit link applied to both. Makes sense. Any chance you know of a conversion for calculating the indirect effects in my case? Thanks again.

I’d look up default link of neg binom in brms. That should help. I’m not at a computer and don’t remember off hand

Hi - that link is broken now… do you still have this code available?

Yes, the function is now re-implemented in the bayestestR-package, the related vignette is here.

1 Like

Hi! Thanks a lot for providing this function! I have two questions related to it

  1. In my mediation model, the mediator is normally distributed and the dependent variable can be considered cumulative.
    bfy ~bf(y~x+m+(1+x+m|ID|Subject), family=“cumulative”)
    bfm ~bf(m~x+(1+x|ID|Subject), family=“gaussian”)
    As these families do not have the same link (cumulative having a logit-link) - can I still use the mediation()-function to calculate the effects (especially the indirect effect)? And if not, do you know a workaround for that?
  2. Is it possible to include covariates into the model als illustrated below? (Please note that I am not including the interaction terms with the covariate as random effect as well as this does not add much to the predictive capacity of the model)
    bfy ~bf(y~xcov1+mcov1+(1+x+m+cov1|ID|Subject), family=“cumulative”)
    bfm ~bf(m~x+(1+x|ID|Subject), family=“gaussian”)
    Thanks a lot for your help!

@SarahD
Dear Sarah,

I came across your post after asking a similar question myself.
Have you eventually found the solution?
I’m losing confidence whether I can fit the model using R at all…arghh…
i would really appreciate if you could share your experience!! Thank you…!

It would be better to start a new question here because the original post here has been marked solved. Preliminary answers to the post above:

  1. I don’t know about the mediation() function but you can calculate an indirect coefficient with two different outcome distributions / link functions.
  2. Yeah.