Hi all,
I am trying to test the following model, and am curious if the code I have written is the appropriate way to represent these effects. We are assuming that the moderators (Z and M) can affect the mediator (Y) and the DV.
Model:
Current code:
model <- '
# Regression equations
M ~ aZ * Z + control_1 + control_2 + control_3
Y ~ bM * M + bX * X + bXM * X:M + bZ * Z + bXZ * X:Z + control_1 + control_2 + control_3
DV ~ cM * M + cX * X + cXM * X:M + cZ * Z + cXZ * X:Z + cY * Y + control_1 + control_2 + control_3
# Mean of X
X ~ X.mean * 1
# Variance of X
X ~~ X.var * X
# Effects on Mediator conditional on moderator
ZtoM.SDlo := ( aZ )
ZtoM.SDhi := ( aZ )
########## Y effects
# Indirect Effects Conditional on Moderator
Y.indirect.SDlo := (bM + bXM * (X.mean - sqrt(X.var))) * ZtoM.SDlo
Y.indirect.SDhi := (bM + bXM * (X.mean + sqrt(X.var))) * ZtoM.SDhi
# Index of Moderated Mediation
index.mod.med: = ( aZ ) * bXM
# Covariance of Exogeneous Variables
Enact_Condition ~~ Gender_code
# Direct Effects Conditional on Moderator
Y.direct.SDlo := (bZ + bXZ * (X.mean - sqrt(X.var)))
Y.direct.SDhi := (bZ + bXZ * (X.mean + sqrt(X.var)))
# Total Effects conditional on moderator
Y.total.SDlo := Y.direct.SDlo + Y.indirect.SDlo
Y.total.SDhi := Y.direct.SDhi + Y.indirect.SDhi
# Proportion Mediated Conditional on Moderator
Y.prop.mediated.SDlo := Y.indirect.SDlo / Y.total.SDlo
Y.prop.mediated.SDhi := Y.indirect.SDhi / Y.total.SDhi
########## DV effects
# Indirect Effects Conditional on Moderator (gender to belonging)
DV.indirect.SDlo := (cX+ cY) * (bM + bXM * (X.mean - sqrt(X.var))) * ZtoM.SDlo
DV.indirect.SDhi := (cX+ cY) * (bM + bXM * (X.mean + sqrt(X.var))) * ZtoM.SDhi
# Index of Moderated Mediation (alternativ test for sign. differences among different moderator levels)
DV.index.mod.med: = ( aZ ) * bXM * cY
# Direct Effects Conditional on Moderator (gender to belonging)
ZtoDV.direct.SDlo := (cZ + cXZ * (X.mean - sqrt(X.var)))
ZtoDV.direct.SDhi := (cZ + cXZ * (X.mean + sqrt(X.var)))
# Direct Effects Conditional on Moderator (threat to belonging)
MtoDV.direct.SDlo := (cM + cXM * (X.mean - sqrt(X.var)))
MtoDV.direct.SDhi := (cM + cXM * (X.mean + sqrt(X.var)))
# Total Effects conditional on moderator
DV.total.SDlo := ZtoDV.direct.SDlo + MtoDV.direct.SDlo + DV.indirect.SDlo
DV.total.SDhi := ZtoDV.direct.SDhi + MtoDV.direct.SDhi + DV.indirect.SDhi
# Proportion Mediated Conditional on Moderator (To match the output of mediate package)
DV.prop.mediated.SDlo := DV.indirect.SDlo / DV.total.SDlo
DV.prop.mediated.SDhi := DV.indirect.SDhi / DV.total.SDhi
'
model.fit <- sem(model = model,
data = data,
se = "bootstrap",
bootstrap = 500)
model.results <- parameterEstimates(model.fit,
boot.ci.type = "bca.simple",
level = .95, ci = TRUE,
standardized = FALSE)
model.results
I am also wondering if it would be possible to represent Z as a categorical variable with 4 categories, using 3 dummy variables, or if this would cause the calculations of the effects to be incorrect?
Alternatively, I am wondering if Z could be replaced with an interaction between two variables, as pictured below, or if this kind of model would be beyond the means of what lavaan can do?
Thank you very very much for your help!