I’m working with a dataset that has three levels: teacher, school, and country. I want to do a Confirmatory Factor Analysis (CFA) using teacher survey responses, but I need the factor scores at the school level. I also want to check for measurement invariance across countries.
I’m using the lavaan package in R because it can handle my complex survey design with the lavaan.survey extension. Right now, I’m using country ID as the group in the CFA function, which lets me do the measurement invariance analysis. But the factor scores are coming out at the teacher level, not the school level like I need.
Does anyone know how to get these factor scores at the school level instead? Here’s a simplified version of what I’m doing:
library(lavaan)
model <- '
teacher_support =~ Q1 + Q2 + Q3
prof_development =~ Q4 + Q5 + Q6 + Q7
'
fit_basic <- cfa(model, data = survey_data, group = 'country_code')
fit_loadings <- cfa(model, data = survey_data, group = 'country_code', group.equal = c('loadings'))
fit_intercepts <- cfa(model, data = survey_data, group = 'country_code', group.equal = c('loadings', 'intercepts'))
# How do I get school-level factor scores?
Any ideas would be really helpful!
yo Ava_Books, ur multilevel CFA sounds tricky! have u tried the ‘mlVAR’ package? it might help with those school-level scores. also, maybe u could use a weighted average of teacher scores for each school? just a thought. keep us posted on how it goes, k? good luck with ur research!
I’ve encountered a similar challenge with multilevel CFA before. One approach you might consider is using a two-step process. First, conduct your CFA at the teacher level as you’re currently doing. Then, aggregate the resulting factor scores to the school level using a method like taking the mean or median of teacher scores within each school.
For the aggregation step, you could use functions like aggregate() or dplyr’s group_by() and summarize(). This method preserves the measurement invariance analysis across countries while giving you school-level scores.
Another option is to explore multilevel SEM packages like ‘xxm’ or ‘nlsem’ in R, which are designed to handle hierarchical structures more directly. These might allow you to specify your model at multiple levels simultaneously.
Remember that aggregating to the school level may affect the reliability and validity of your measures, so it’s crucial to report how you derived the school-level scores and consider the implications for your interpretations.
Hey Ava_Books! Fascinating project you’ve got there!
I’m really intrigued by your multilevel CFA approach. Have you considered using a different package that might be better suited for multilevel modeling? Maybe something like ‘lme4’ or ‘nlme’ could help you get those school-level factor scores you’re after?
I’m curious, though - why do you specifically need the factor scores at the school level? Are you planning to use them in further analyses? It might be worth exploring if there’s a way to incorporate the school-level structure directly into your CFA model.
Oh, and another thought - have you looked into using Mplus? I’ve heard it’s pretty good at handling complex multilevel structures in CFA. Might be worth checking out if R isn’t giving you what you need.
Anyway, I’d love to hear more about your project and what you end up doing. Keep us posted on how it goes, okay? Good luck with your analysis! 