Random slopes in multilevel models

69 views
Skip to first unread message

Steffen Nestler

unread,
Jun 14, 2026, 10:29:29 AMJun 14
to lavaan
Hi Terrence, hi Yves,

I know that it is not possible to estimate multilevel SEMs with lavaan. However, I was wondering whether there is already a supported lavaan-syntax for such a model that I can use with lavaanify and lavMatrixRepresentation? For instance, something like this 

m <- 'level: 1
fw1 =~ happy + calm
fw2 =~ active + relaxed
s | fw2 ~ fw1

         level: 2
fb1 =~ happy + calm
fb2 =~ active + relaxed
fb2 ~ fb1
        s ~~ s'

test <- lavaanify( m )
lavMatrixRepresentation( test )

where "s |" is the random slope.

Thank you!
Steffen

Yves Rosseel

unread,
Jun 21, 2026, 2:28:29 PMJun 21
to lav...@googlegroups.com, steffen...@uni-muenster.de
Hello Steffen,

Yes, there is syntax, although it was temporarily disabled in the new
parser, but it is still available through the old parser. The syntax
looks like this:

model <- '
level: 1
fw =~ y1 + y2 + y3 + y4
fw ~ rv("s1")*x1 + rv("s2")*x2

level: 2
fb =~ y1 + y2 + y3 + y4

# fixed effects
s1 ~ 1
s2 ~ 1

# random effects variances
s1 ~~ s1
s2 ~~ s2
s1 ~~ s2
'

The 'rv("XX")' modifier indicates that the parameter is 'random', and
the "XX" variable becomes a variable at the between level.

So for now, you need to use parser = "old" to use this syntax. In attach
a minimal example script (ignore the many start*() values)

Yves.
> --
> You received this message because you are subscribed to the Google
> Groups "lavaan" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to lavaan+un...@googlegroups.com
> <mailto:lavaan+un...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/lavaan/
> e1bb20ca-e3ab-4af0-9545-423d1fdee3c0n%40googlegroups.com <https://
> groups.google.com/d/msgid/lavaan/e1bb20ca-
> e3ab-4af0-9545-423d1fdee3c0n%40googlegroups.com?
> utm_medium=email&utm_source=footer>.

--
Yves Rosseel
Department of Data Analysis, Ghent University
ex9.8_bal.dat
ex9.8_bal.R

Steffen Nestler

unread,
Jun 22, 2026, 10:14:21 AMJun 22
to lavaan
Hi Yves,

Nice. Thanks!

Steffen
Reply all
Reply to author
Forward
0 new messages