I'm trying to build a SEM that looks like the picture shown below:
Where:
- $X$ and $X^2$ are the independent variables
- $Y$ is the dependent variable
- $M_1$ and $M_2$ are the mediators
- $W$ is a moderator
None of the default mediation packages that I've tried so far support such a structure so I'm using lavaan SEM instead. I've been reading up on Hayes and have figured out the model without the moderator:
# direct effect
Y ~ cprime1*X + cprime2*X2 + controls
# mediator 1 paths
M1 ~ a1*X+a2*X2 + controls
Y ~ b1*M1
# mediator 2 paths
M2 ~ a1prime*X + a2prime*X2 + d*M1 + controls
Y ~ b2*M2
# indirect effect (a*b) using the Hayes2010 formula (Table 1)
ab := (a1 + 2*a2*X)*b1 + (a1prime + 2*a2prime + (a1+2*a2*X)*d ) * b2
# total effect
cprime := (cprime1+2*cprime2)
total := cprime + (ab)
I'm aware of how to moderate with 1 input variable, for instance for M1 you'd have something like:
M1 ~ a1*X1 + a2*W + a3*X1:W + controls
But it's unclear to me how one would add the moderators for X2 in these and the other parts of the model.