issues with 'group.label' argument in lavaan()

464 views
Skip to first unread message

Fabrício Fialho

unread,
Mar 24, 2017, 3:14:16 AM3/24/17
to lavaan
Hi all,

I have been experiencing an issue running multiple group analysis with recent version of lavaan. Basically, I receive an error message if I include a 'group.label' argument in my code.


A reproducible example:

Let say I aim to replicate the Holzinger and Swineford analysis for multiple groups -- in this case, the two different schools in the data.

----------------------------------------------------------------------------------------------------
# Model

HS.model <- '
             visual  =~ x1 + x2 + x3
             textual =~ x4 + x5 + x6
             speed   =~ x7 + x8 + x9
            '



## If I just include 'group', everything works fine.

fit1 <- lavaan(HS.model, data=HolzingerSwineford1939,
               group="school",
               auto.var=TRUE, auto.fix.first=TRUE,
               auto.cov.lv.x=TRUE)
summary(fit1, fit.measures=TRUE)




## However, if I name the groups using 'group.label', I receive an error message like:

fit2 <- lavaan(HS.model, data=HolzingerSwineford1939,
              group="school", group.label=c("Pasteur","Grant-White"),
              auto.var=TRUE, auto.fix.first=TRUE,
              auto.cov.lv.x=TRUE)


Error in lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan ERROR: no group levels left; check the group.label argument
In addition: Warning message:
In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some group.labels do not appear in the grouping variable: pasteur grant-white

----------------------------------------------------------------------------------------------------


As trivial as this might go --in this example I could just get rid of 'group.label' and I would obtain the same results-- things get a bit more complicate if, for instance, I set Grant-White as the reference group using ' group.label=c("Grant-White", "Pasteur")' in measurement invariance study.

Is there any change in how to use group.label in the most recent lavaan version? I used to use group.label to re-order groups in the analysis (to set a different group as the reference rather than the group that occurs first in the dataset). I could run codes like this in the recent past but tried to re-run my analyses now (after updating packages) and got this message so I guess there are changes in how lavaan handles group.label arguments.





Just for the sake of completeness:

> sessionInfo()
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 8 (jessie)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8   
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8  
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                
 [9] LC_ADDRESS=C               LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets
[6] methods   base    

other attached packages:
[1] lavaan_0.5-23.1097

loaded via a namespace (and not attached):
[1] MASS_7.3-45    tools_3.3.3    mnormt_1.5-5 
[4] pbivnorm_0.6.0 stats4_3.3.3   quadprog_1.5-5


Terrence Jorgensen

unread,
Mar 24, 2017, 11:46:12 AM3/24/17
to lavaan
I tried this with the latest development version (0.6-1.1118) and got the same error you did.  Yves has been doing some surgery on how lavaan handles groups, and I'm not sure where the error originates, but the problem is that the group labels you provide (though correct) are being compared to all-lowercase versions.  I'll post a suggested fix on github, but in the meantime, if your rows of data remain in the same order, the groups should always be in the same order in your results, too.

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

Fabrício Fialho

unread,
Mar 24, 2017, 6:18:00 PM3/24/17
to lavaan
Thanks for the feedback, Terrence.

Just in case it may be of help to track back where the error comes from:
The problem occurs when I use lavaan version 0.5-23-1097. I reinstalled lavaan 0.5-22 from the Cran Archive (https://cran.r-project.org/src/contrib/Archive/lavaan/) and it runs smoothly.

Fabrício Fialho

unread,
May 7, 2017, 10:59:10 PM5/7/17
to lavaan
Just an update on this front:
 
Installing the most recent versions of lavaan and semTools using 

install.packages("lavaan", repos = "http://www.da.ugent.be", type = "source")
devtools::install_github("simsem/semTools/semTools")

leads to the following error in a multiple-group analysis:

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: no group levels left; check the group.label argument
In addition: Warning message:
In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some group.labels do not appear in the grouping variable: group1 group2


It does not occur if I roll back to lavann 0.5-22 and semTools 0.4-14.


(Trying to install semTools 0.4-15 returns a non-zero exit status error.)


> sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
[5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
[9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
  [1] semTools_0.4-15.910 lavaan_0.6-1.1125  

loaded via a namespace (and not attached):
  [1] httr_1.2.1      compiler_3.4.0  R6_2.2.0        tools_3.4.0     withr_1.0.2     curl_2.6        memoise_1.1.0  
[8] mnormt_1.5-5    pbivnorm_0.6.0  git2r_0.18.0    digest_0.6.12   stats4_3.4.0    devtools_1.12.0 quadprog_1.5-5 

Terrence Jorgensen

unread,
May 11, 2017, 4:16:29 AM5/11/17
to lavaan
Installing the most recent versions of lavaan and semTools using leads to the following error in a multiple-group analysis:

Error in lav_data_full(data = data, group = group, cluster = cluster,  : 
  lavaan ERROR: no group levels left; check the group.label argument
In addition: Warning message:
In lav_data_full(data = data, group = group, cluster = cluster,  :
  lavaan WARNING: some group.labels do not appear in the grouping variable: group1 group2

Right, this is the same error, and if I remember correctly (fiddled around with it a while ago), I think it only occurs with 2-group models.  The issue is posted on github:

Reply all
Reply to author
Forward
0 new messages