Hello everyone,
I'm doing some analyses using lavaan. I have a dataset that has a large amount of groups. I wanted to investigate fitting a cfa model to each group individually (yes I'm aware of multigroup CFA).
I wrote this code:
mydata %>%
group_by(country) %>%
nest() %>%
mutate(cfa = map(.x = data, .f = cfa, model = Model_4))
This returns some warnings. Which didnt strike me out of the ordinary. However, when I then tried a for loop:
cfa_list <- list()
for (i in 1:length(levels(data$country))) {
data <- data%>%
filter(country == levels(data$country)[i])
cfa_list[[i]] <- cfa(model = Model_4,
data = data)
}
Using the loop, I get no warnings from Lavaan. Is this somehow not equivalent? I tried reproducing it but couldn't. Perhaps with a dataset that also contains a larger amount of groups (10+)?