This should probably be migrated to StackOverflow since it is about software, but:
You could do this in the R package lavaan
. In your model, you would first specify models for M1
, M2
, and Y
. We will want to label all the paths, as well. I will label c' as cp
, for "c-prime":
M1 ~ a1 * X
M2 ~ a2 * X + d21 * M1
Y ~ cp * X + b1 * M1 + b2 * M2
The indirect effect, ind_eff
is then defined, per Hayes, as a1 * d21 * b2
:
ind_eff := a1 * d21 * b2
You need to put this all in a string object:
model <- "
M1 ~ a1 * X
M2 ~ a2 * X + d21 * M1
Y ~ cp * X + b1 * M1 + b2 * M2
ind_eff := a1 * d21 * b2
"
Then you just run the model using bootstrapped confidence intervals to get the confidence interval for the indirect effect (ind_eff
):
fit <- lavaan::sem(model = model, data = dat, se = "boot", bootstrap = 5000)
Where dat
is the name of your data frame and 5000
is the number of bootstrap resamples you would like to do (this will likely take a few minutes).
To look at your results, you can call:
lavaan::parameterEstimates(fit, boot.ci.type = "bca.simple")