level: 1
...
level: 2
...
'
summary(... cluster = "cluster")lavMed <- '
level: 1
# direct effect
Resp ~ c*Pred
# mediator
Med ~ a*Pred
Resp ~ b*Med
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
level: 2
'lavMed <- '
level: 1
# direct effect
Resp ~ c*Pred
# mediator
Med ~ a*Pred
Resp ~ b*Med
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
level: 2
subID ~ 1
'
fit <- sem(lavMed,
data = medDf,
group = "Mod", cluster = "subID")
summary(fit)Error in ov.names.l[[g]] : subscript out of boundsit seems to require that you have some variables included in level 2. However, my multilevel moderated mediation is all level 1 variables.
note that in level: 1 the colon follows the level keyword; if you
type level 1:, you will get an error
you must specify a model for each level; the following syntax is not allowed and will produce an error:
model <- '
level: 1
fw =~ y1 + y2 + y3
fw ~ x1 + x2 + x3
level: 2
'
if you do not have a model in mind for level 2, you can specify a saturated level by adding all variances and covariances of the endogenous variables (here: y1, y2 and y3):
model <- '
level: 1
fw =~ y1 + y2 + y3
fw ~ x1 + x2 + x3
level: 2
y1 ~~ y1 + y2 + y3
y2 ~~ y2 + y3
y3 ~~ y3could you please further elaborate in regard to this statement?