This vignette shows examples of two-level (multilevel) models, with
and without random slopes, with both continuous and ordinal data.
Two-level models are specified with separate models for the within
(level: 1) and between (level: 2) levels, and
the cluster variable is given by the cluster argument.
two_level_model <- "
level: 1
fw =~ y1 + y2 + y3
fw ~ x1 + x2 + x3
level: 2
fb =~ y1 + y2 + y3
fb ~ w1 + w2
"Random slopes are specified with rv() modifiers at level
1, where the random slopes (here s1 and s2)
are variables at level 2.
slopes_model <- '
level: 1
fw =~ y1 + y2 + y3
fw ~ rv("s1")*x1 + rv("s2")*x2 + x3
level: 2
fb =~ y1 + y2 + y3
fb ~ w1 + w2
# the random slopes are latent variables at the between level
s1 + s2 ~ w1 + w2
'