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

79 views

### Yingkai Yang

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

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