Error troubleshooting: between-level (only) variables have non-zero variance at the within-level

47 views
Skip to first unread message

Ari Fodeman

unread,
Aug 25, 2025, 11:39:59 AM (13 days ago) Aug 25
to lavaan
Hey y'all,

I'm trying to run a simple multilevel multiple regression in Lavaan, but getting the error:

"
Error: lavaan->lav_data_full():  
   Some between-level (only) variables have non-zero variance at the
   within-level. Please double-check your data.
"

For this model, we have school-level policies predicting a student-level outcome. Within a school, there is no variation in the school policy because the school only has one observation (e.g., 'for the past school year, did you have a typing class?'); how would I specify this kind of model? What I've written is:

level: 1
Student_Outcome ~ 1
level: 2
Student_Outcome ~ School_Policy_1 + School_Policy_2 + School_Policy_3

Felipe Vieira

unread,
Aug 25, 2025, 12:28:50 PM (13 days ago) Aug 25
to lav...@googlegroups.com
Hi Ari, 

With respect to the error message, it means at least one of your school-policy predictors isn't constant within schools. Lavaan will check that as mentioned by Yves here (https://groups.google.com/g/lavaan/c/5CaX_CkyWOs). So, it expects variables listed under level 2 to have zero within-school variance. 

Best, 
Felipe. 



--
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.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/f706db62-9a91-485f-b3b2-2fded09ab2a5n%40googlegroups.com.
Message has been deleted

Ari Fodeman

unread,
Aug 26, 2025, 4:09:07 PM (12 days ago) Aug 26
to lavaan
Is that the only possible reason? I've triple checked that if a row (student observation) is associated with a school, another row associated with the same school is not associated with a different school-level response. I could be missing a mistake in my code integrating the student- and school-level responses, though.

Jeremy Miles

unread,
Aug 26, 2025, 4:12:08 PM (12 days ago) Aug 26
to lav...@googlegroups.com

You can check with something like:

df %>% dplyr::group_by(school) %>% dplyr::summarise(sd = sd(school_level_var))

All of the standard deviations should be zero, for every school level   variable .


Jeremy

Message has been deleted

Ari Fodeman

unread,
Aug 29, 2025, 3:29:56 PM (9 days ago) Aug 29
to lavaan
Aha, I figured it out! Two of the school policies are actually segmented by grade level. My data manager created a single version of each school policy, though, that varied not only by school, but by the grade of the student, such that students in the same school but different grades might have different school policies.

Should I use the original grade-specific variables, and make Grade a control variable for those policies? Make Grade a cross-classified cluster? Make grade a group for multigroup modeling? We have K through 12th grade.

Reply all
Reply to author
Forward
0 new messages