This was a repeated measures design and clustering is according to individual participants, identified by the variable ‘ID’.
Without a model initially in mind for level:2, it’s been saturated as recommended here
https://lavaan.ugent.be/tutorial/multilevel.htmlMy model, which appears to be running correctly, is then:
model <- '
level:1
# direct effects
DV ~ b*M1 + c*M2 + d*CON
# mediator models
M1 ~ a1*CON
M2 ~ a2*CON
# indirect effects
indirect1 := a1*b
indirect2 := a2*c
# total effects
total := d + (a1*b) + (a2*c)
# covariances
M1 ~~ M2
level:2
DV ~~ DV + M1 + M2
M1 ~~ M1 + M2
M2 ~~ M2
'
fit.model <- sem(model = model,
data = data,
missing = "ml",
cluster = "ID")But now I’d like to include demographic covariates, such as age (C1), gender (C2), and income (C3). But these are between participant characteristics and I’m coming unstuck trying to add them into the model. I think they have to go in level:2 but I can’t find an example where this has been done and I’m unclear on the syntax required.
Any help would be very gratefully appreciated.
Many thanks!
Alex