Monte Carlo confidence intervals for direct effect, total effect, and the proportion mediated

79 views
Skip to first unread message

Yingkai Yang

unread,
Jul 5, 2019, 11:05:54 PM7/5/19
to lavaan
Dear all,

I have searched how to calculate the Monte Carlo confidence intervals for indirect effect, and found the below code, and it worked, however, I do not know how to calculate  the Monte Carlo confidence intervals for direct effect, total effect, and the proportion mediated(indirect effect/total effect).

set.seed(1234)
<- rnorm(100)
<- 0.5*+ rnorm(100)
<- 0.7*+ rnorm(100)
Data <- data.frame(= X, Y = Y, M = M)
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)
prop := ab/total
'
fit 
<- sem(model, data = Data)

#Monte Carlo confidence intervals for indirect effect
med 
<- 'a*b'
myParams 
<- c("a","b")
myCoefs 
<- coef(fit)[myParams]
myACM 
<- vcov(fit)[myParams, myParams]
monteCarloMed
(med, myCoefs, ACM = myACM)


Thank you so much in advance.
best,

Terrence Jorgensen

unread,
Jul 6, 2019, 5:23:13 AM7/6/19
to lavaan
I do not know how to calculate  the Monte Carlo confidence intervals for direct effect, total effect, and the proportion mediated(indirect effect/total effect).

Not sure why you'd need a Monte Carlo CI for a direct effect, that would just add noise to the Wald z test you get from summary().  But you can feed any function of parameters as the first argument to monteCarloMed().  Notice how the "med" object is the same equation you use to define "ab" in your syntax?  Do the same thing with your other quantities (including simple "c" if you want a less powerful test than the Wald z test that makes the exact same assumptions as the Monte Carlo CI).

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Yingkai Yang

unread,
Jul 6, 2019, 7:40:20 AM7/6/19
to lavaan
Thanks!! Did not know this before(just a beginner). I have a sample with n >10000, I assume the results of the effects (include the indirect effect) and the CIs from the Wald z test are cool?  Do not need bootstrap or Monte Carlo CI ?

在 2019年7月6日星期六 UTC+8下午5:23:13,Terrence Jorgensen写道:
Reply all
Reply to author
Forward
0 new messages