问题
How can I create a first stage mediated moderation model in R? I have been trying to write a model like this in lavaan,
but I am running into issues trying to adapt the code from the laavan webpage.
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)
summary(fit)
回答1:
I have full code, example datasets, and a .pdf walk-through of how to do this here.
Relevant portion from the .pdf:
“First Stage” Moderated Mediation (PROCESS Model 7)
The a path of a mediation model might be moderated by some other variable. Hayes (2015) calls this “first stage” moderated mediation, since the moderation happens on the first path. The code is quite similar, except that now you must first create an interaction variable between the independent variable and moderator variable:
data$ivxmod <- data$iv*data$mod
I named the new variable “ivxmod
,” but you can name it whatever you’d like. Just remember to use the same variable name in the code below. Specifying the model is very similar to the basic mediation model:
model7 <- "med ~ a1*iv + a2*mod + a3*ivxmod
dv ~ cp*iv + b*med
imm := a3*b"
You can see that now the mediator is being predicted by the independent variable, moderator, and the interaction between the two. The second line is the same as basic mediation. The third line is defining the index of moderated mediation by simply multiplying the weight for the interaction on the a path with the regression weight on the b path. Fitting and examining the model is about the same code as before:
set.seed(1839)
model7.fit <- sem(model=model7, data=data, se = "boot", bootstrap = 5000)
model7parameters <- parameterEstimates(model7.fit, boot.ci.type="bca.simple")
model7parameters # all parameters
model7parameters[14,c(1,5,9,10)] # just stuff relevant for index of moderated mediation
来源:https://stackoverflow.com/questions/43432661/creating-a-first-stage-mediated-moderation-model-syntax-issues