Bayesian Mediation Analysis With Latent Variables

94 views
Skip to first unread message

Julian Gaviria

unread,
Jan 9, 2021, 12:37:06 PM1/9/21
to blavaan
Dear list members,

I wonder whether I could run a mediation Analysis including latent variables in blavaan, such as it is easily implemented with lavaan :
library(lavaan)
  model <- '
   # latent variables
     X =~ x1 + x2 + x3
     M =~ y1 + y2 + y3 + y4
     Y =~ y5 + y6 + y7 + y8
   
  fit <- sem(model,data=PoliticalDemocracy)
  summary(fit)
  
  model <- ' # direct effect
             Y ~ c*X
           # mediator
             M ~ a*X
             Y ~ b*M
           # indirect effect (a*b)
             ab := a*b
           # total effect
             total := c + (a*b)
         '
  fit <- sem(model, data = PoliticalDemocracy)
  summary(fit)

P.D. I think one option in the Bayesian context would be the R2OpenBUGS package:

However, it would be nice to know whether I could use blavaan for the same analysis. 

Thanks in advance and the best regards,  

Mauricio Garnier-Villarreal

unread,
Jan 9, 2021, 2:03:29 PM1/9/21
to blavaan
Yes, you can directly estimate this in blavaan, and no need to use boostrap or monte-carlo method. The inference from the posterior for the indirect effects have no assumption on its distribution

Not sure why you have 2 syntaxes called model, you only need 1

library(blavaan)
  model <- '
   # latent variables
     X =~ x1 + x2 + x3
     M =~ y1 + y2 + y3 + y4
     Y =~ y5 + y6 + y7 + y8
 # direct effect
             Y ~ c*X
           # mediator
             M ~ a*X
             Y ~ b*M
           # indirect effect (a*b)
             ab := a*b
           # total effect
             total := c + (a*b)
         '
  fit <- bsem(model, data = PoliticalDemocracy, std.lv=T)
  summary(fit)

Julian Gaviria

unread,
Jan 10, 2021, 5:49:25 AM1/10/21
to blavaan
Thanks Mauricio,

It nicely worked out. Indeed, I had a typo with the string : "model <- ' # direct effect".

Best regards,
Reply all
Reply to author
Forward
0 new messages