I have a repeated measures crossover design where two treatments were delivered to all participants, and measurements of the mediator M and outcome Y were taken following each treatment. I also have a moderator W which moderates the influence of the treatment X on the mediator M. Finally, I have a variable A representing the randomized order of the treatments and we might want to control for its influence on M or Y.
So, if we ignore the multi-level aspect for a moment, a simple lavaan specification might look like
M ~ a1*X + a2*W + a3*X:W + A
Y ~ c*X + b*M + A
indirect_effect := a1*b
direct_effect := c
total_effect := a1*b +ac
moderation_effect := a3*b
So far so good, I think? However, the data are clustered by subject, so we need to design a multi-level model to represent that.
The moderator W is a subject-level (level 2) trait variable, and the order A, being the randomized order of treatments, is also at subject-level. Treatment X, mediator M, and outcome Y are treatment-level (level 1) variables.
So how can I create a multi-level version of the model above? My intuition is to just separate out those two models into separate level 1 and level 2 models, like:
level: 1 # measurement-level
M ~ a1*X + a3*X:W
Y ~ c*X + b*M
level: 2 # subject-level
M ~ a2*W + A
Y ~ A
indirect_effect := a1*b
direct_effect := c
total_effect := a1*b +ac
moderation_effect := a3*b
Is this correct? I'm worried that we might not control for the main effect of W on M when they're specified in two different equations, or that splitting the two equations up into levels specified separately isn't how this should work. It's quite different to lme4 syntax, where I might specify each as
M ~ X + W + X:W + A + (1 | SubjectID)
Y ~ X + M + A + (1 | SubjectID)
Am I right in thinking the last model specified in lavaan is equivalent to the lme4 syntax just above, or is there something I've got wrong in the lavaan syntax?