Multi group Multilevel Analysis - Degrees of freedom

210 views
Skip to first unread message

Nicole El La

unread,
Mar 28, 2022, 12:14:06 PM3/28/22
to lavaan
Hi y'all,

I am running a multi group multilevel analysis to compare mediation models. The problem is, that without the "multi group", my model is saturated and my df = 0 (number of model parameters = 14). 
This is the case for this syntax:
"mod1 <- '
level: 1
Y ~ a*X + f*M
M ~ j*X

level: 2
# unconstrained covariance on the between level
Y ~~ X + M
X ~~ M

#new parameter
IE1 := j*f
TE1 := IE1 + a
'
mod01 <- sem(mod1, dat, cluster = "vpnr01", bootstrap = 1000)
summary(mod01, fit.measures = T, standardized = T)"

When I am now adding the groups, my model is not defined with df = -1 (number of model parameters = 28). This is the syntax I am using:
"mod2 <- '
group: nv
level: 1
Y ~ a*X + f*M
M ~ j*X

level: 2
# unconstrained covariance on the between level
Y ~~ X + M
X ~~ M

# Neue Parameter
IE1n := j*f
TE1n := IE1n + a

group: v
level: 1
Y ~ b*X + g*M
M ~ k*X

level: 2
# unconstrained covariance on the between level
Y ~~ X + M
X ~~ M

# Neue Parameter
IE1v := k*g
TE1v := IE1v + b
'
mod02 <- sem(mod2, dat, group = "vic", cluster = "vpnr01", bootstrap = 1000)
summary(mod02, fit.measures = T, standardized = T)"

Do you have any idea, where I did lose my degree of freedom?
I have the same problem with all of my multi group multilevel analysis, this is just one example.

Thank you so much

Terrence Jorgensen

unread,
Mar 29, 2022, 10:30:39 AM3/29/22
to lavaan
Try setting fixed.x=FALSE.  Maybe lavaan hasn't worked out detecting this inconsistency (estimating the variance of X at Level 2) in the case of multigroup+multilevel models.

But if you have no model at Level 2, you could fit a single-level model, and the cluster= argument will trigger cluster-robust SEs and tests.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Yves Rosseel

unread,
Apr 25, 2022, 6:26:07 AM4/25/22
to lavaan
This was a df counting error in lavaan (when nlevels > 1L, ngroups > 1L and fixed.x = TRUE). Now fixed in the github version.
Yves.

Ale Dea

unread,
Apr 30, 2022, 11:56:38 AM4/30/22
to lavaan
Dear all,

I see that in this example, it was set  cluster = "vpnr01", bootstrap = 1000 in the options. Does lavaan support bootstrap cluster standard errors?

Thanksa

Reubs Walsh

unread,
Jan 12, 2023, 1:46:00 PM1/12/23
to lavaan
Hi Yves, et al,
I'm having a similar issue – when testing measurement invariance between groups, as I add equality constraints between the groups, the DF increases, as you'd expect. But if I then remove the specification of groups (i.e. in the lavaan(), cfa() or sem() etc functions, the 'groups=' argument), having incrementally set everything in the model to equality between the groups, this change cuts the DF roughly in half. Is there still a d.f. counting error in the CRAN version 0.6-13? Or have I missed something?
Thanks,
Reubs

Best Wishes,

Reubs Walsh (They/Them)

________________________________

Reubs J Walsh BA (Oxon) MSc (Lond)  

Promovendus, KNOP (Clinical, Neuro- and Developmental Psychology) 

Faculteit der Gedrags- en Bewegingswetenschappen (Faculty of Behavioural and Movement Sciences)
Vrije Universiteit Amsterdam


Terrence Jorgensen

unread,
Jan 19, 2023, 4:02:35 AM1/19/23
to lavaan
If I understand correctly, you have a multigroup CFA/SEM in which all parameters are equal across groups, and a single-group CFA/SEM that basically corresponds to the model fitted in either of the multiple groups?  So you are estimating the same number of parameters in each model (minus any equality constraints placed on estimated parameters)?  In that case, you should have way more df in the multigroup SEM because you are reproducing twice as many summary statistics with the same number of parameters.

Yves Rosseel

unread,
Jan 19, 2023, 5:14:00 AM1/19/23
to lav...@googlegroups.com
On 1/12/23 19:46, Reubs Walsh wrote:
> But if I then remove the specification of
> groups (i.e. in the lavaan(), cfa() or sem() etc functions, the
> 'groups=' argument), having incrementally set everything in the model to
> equality between the groups, this change cuts the DF roughly in half.

If you removed the 'group=' argument, it seems logical that the DF cuts
(roughly) in half.

For example:

HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
fit <- cfa(HS.model, data = HolzingerSwineford1939, group = "school")
fit
# DF = 48

fit <- cfa(HS.model, data = HolzingerSwineford1939)
fit
# DF = 24

But perhaps I misunderstood. Can you show us the syntax, and what you
were expecting?

Yves.
Reply all
Reply to author
Forward
0 new messages