I'm trying to do a multilevel structural equation model using a data set with observations from 32 different countries. I cluster the model by country. The model runs but on the output it says there were 29 clusters. Would there be a way to check which clusters are being dropped and where listwise deletion is removing cases?
fit.3b <- sem(mod3, data=data_merge, meanstructure=TRUE, std.lv=TRUE, sampling.weights="WEIGHT", cluster = "country", optim.method = "em")
summary(fit.3b, fit.measures=TRUE, estimates=TRUE)
I was expecting there to be 32 clusters used in the output. I removed countries that were missing exogenous variables.
For any fitted model, you can extract the vector of cluster IDs in that model:
library(lavaan)
example(Demo.twolevel)
lavInspect(fit, "cluster.id")
To extract the missing cluster(s), you could use setdiff()
to compare that to the unique()
values in your data's cluster-ID variable.
setdiff(unique(Demo.twolevel$cluster), # what's in here...
lavInspect(fit, "cluster.id")) # but not in here?