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 bounds
it 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:
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):
could you please further elaborate in regard to this statement?