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)
X <- rnorm(100)
M <- 0.5*X + rnorm(100)
Y <- 0.7*M + rnorm(100)
Data <- data.frame(X = 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,