problem with running multi group cfa in lavaan

2,974 views
Skip to first unread message

paul murimi

unread,
Sep 8, 2016, 8:32:12 AM9/8/16
to lavaan
Hi everyone

Please help
Am trying to run Multiple Group CFA for ordinal data in lavaan, the following is the error am getting.

model1.fit <- cfa(model1, ordered = c("gh1","gh2","gh3","gh4","gh5","gh6.1","gh7","gh8","gh9","gh10","gh11","gh12"),data=dat, group = "countrycode1",missing = "pairwise") Error in lav_samplestats_step1(Y = Data, ov.names = ov.names, ov.types = ov.types, : lavaan ERROR: some categories of variable `gh10' are empty in group 1; frequencies are [139 23 7 0]



Terrence Jorgensen

unread,
Sep 9, 2016, 4:32:48 AM9/9/16
to lavaan
Error in lav_samplestats_step1(Y = Data, ov.names = ov.names, ov.types = ov.types,  : 
  lavaan ERROR: some categories of variable `gh10' are empty in group 1; frequencies are [139 23 7 0]

As the error message implies, you don't have the same number of categories in each group.  That means you don't have the same parameters in each group, which is a typical requirement for SEM program (although it is possible in principle to fit different models to different groups, across-group constraints might not be sensible).  The usual solution would be to find out what your frequencies are in each group, then collapse a pair of adjacent categories when one group has zero in that category.  You can print a 2-way table of each categorical variable by group, or you can use the lavTables() function.

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

paul murimi

unread,
Sep 21, 2016, 4:16:56 AM9/21/16
to lavaan
Thanks Terrence,

I was unable to collapse a pair of adjacent categories when one group has zero in a category in lavaan. I identified those groups with zero frequencies.
When I get rid of those questions with zero frequencies in these groups, the lavaan is converging. I will appreciate, if can guide me how to collapse them, for lavaan to converge.
Thanks.

Regards,
Paul

paul murimi

unread,
Sep 21, 2016, 4:25:26 AM9/21/16
to lavaan

Thanks Terrence,

I was unable to collapse a pair of adjacent categories when one group has zero in that category. I identified those questions with zero frequencies in some groups and when I get rid of them, the lavaan converge. I will appreciate if you can guide me on how to collapse a pair of adjacent categories, so when I include all the question the lavaan will converge too. Thanks.

Regards,
Paul 


Terrence Jorgensen

unread,
Sep 21, 2016, 4:48:18 AM9/21/16
to lavaan
I identified those questions with zero frequencies in some groups

If you know what those variables are, then you can print a 2-way table to see which categories are empty

table(myData$var1, myData$group)

Assuming "var1" has 4 categories {0, 1, 2, 3}, and Category 3 is empty in one of the groups, then you can collapse it with Category 2:

myData$var1.collapsed <- ifelse(myData$var1 == 3, yes = 2, no = myData$var1)

Or you could use the recode() function in the car package, but it is probably simpler to use ifelse() if the collapsing is not complicated.  Some complications could be 
  • The empty category is not one of the extreme low/high values, so you would have to choose which category to collapse it with
  • The data are binary, in which case collapsing to a single category makes it a constant, not a variable.  In that case, you would just have to remove that variable from your model (because it is a constant in one group, so there is no information to compare across groups).

paul murimi

unread,
Sep 22, 2016, 2:40:45 AM9/22/16
to lavaan

Thanks Terrence,

I appreciated your effort in helping me solve this problem. The problem is now solved.

Regards,
Paul

Jorge Sinval

unread,
Jun 14, 2017, 10:18:42 AM6/14/17
to lavaan
I had the same error, but no 0 cells appeared, although some frequencies were very low. After collapsing, everything ran smoothly!  

Bharat Ram Ammu

unread,
Jun 2, 2018, 8:52:05 PM6/2/18
to lavaan
This is a really good idea. I had a similar problem and will take your suggestion as well. Thanks Terrence!
Reply all
Reply to author
Forward
0 new messages