runMI output summary not working

262 views
Skip to first unread message

Mia DeCataldo

unread,
Jun 5, 2024, 11:54:14 AM6/5/24
to lavaan
Hi all, 
I am running into an issue with the summary() function for a lavaan.mi object. I've seen other posts with similar issues, but unfortunately I'm still struggling to resolve it. From what I've read, the error is due to summary() misinterpreting the lavaan.mi object as a lavaanList object when the semTools package is loaded via namespace before it is attached. However, in my case when the semTools packages is attached first, I'm given an error in the parameter estimates. I've attached code + output from the runMI example code below. Is there a way I can avoid either of these issues? thanks, Mia 

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8  
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] compiler_4.4.0    tools_4.4.0       rstudioapi_0.16.0 lavaan_0.6-17    
[5] mnormt_2.1.1      pbivnorm_0.6.0    stats4_4.4.0      quadprog_1.5-8  
> showMethods(summary)

Function "summary":
 <not an S4 generic function>
> library(semTools)

> showMethods(summary)
Function: summary (package base)
object="ANY"
object="BootMiss"
object="EFA"
object="FitDiff"
object="lavaan"
object="lavaan.mi"
object="lavaanList"
object="measEq.syntax"
object="mle"
object="Net"
object="permuteMeasEq"
object="twostage"

this works, but does not give parameter estimates 
# Using example code from runMI()
> ## Not run:
> ## impose missing data for example
> HSMiss <- HolzingerSwineford1939[ , c(paste("x", 1:9, sep = ""),
+                                       "ageyr","agemo","school")]
> set.seed(12345)
> HSMiss$x5 <- ifelse(HSMiss$x5 <= quantile(HSMiss$x5, .3), NA, HSMiss$x5)
> age <- HSMiss$ageyr + HSMiss$agemo/12
> HSMiss$x9 <- ifelse(age <= quantile(age, .3), NA, HSMiss$x9)
> ## specify CFA model from lavaan's ?cfa help page
> HS.model <- '
+   visual  =~ x1 + x2 + x3
+   textual =~ x4 + x5 + x6
+   speed   =~ x7 + x8 + x9
+ '
> ## impute data within runMI...
> out1 <- cfa.mi(HS.model, data = HSMiss, m = 20, seed = 12345,
+                miArgs = list(noms = "school"))
Loading required namespace: Amelia
##
## Amelia II: Multiple Imputation
## (Version 1.8.2, built: 2024-04-10)
## Copyright (C) 2005-2024 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
##
> summary(out1)
lavaan.mi object based on 20 imputed data sets.
See class?lavaan.mi help page for available methods.

Convergence information:
The model converged on 20 imputed data sets

Rubin's (1987) rules were used to pool point and SE estimates across 20 imputed data sets, and to calculate degrees of freedom for each parameter's t test and CI.

Parameter Estimates:

Error in if (categorical.flag) { : argument is of length zero

> summary(out1, fit.measures = TRUE)
lavaan.mi object based on 20 imputed data sets.
See class?lavaan.mi help page for available methods.

Convergence information:
The model converged on 20 imputed data sets

Rubin's (1987) rules were used to pool point and SE estimates across 20 imputed data sets, and to calculate degrees of freedom for each parameter's t test and CI.

Model Test User Model:

  Test statistic                                61.551
  Degrees of freedom                                24
  P-value                                        0.000

Model Test Baseline Model:

  Test statistic                               636.751
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.937
  Tucker-Lewis Index (TLI)                       0.906

Root Mean Square Error of Approximation:

  RMSEA                                          0.072
  Confidence interval - lower                    0.050
  Confidence interval - upper                    0.095
  P-value H_0: RMSEA <= 0.05                     0.049

Standardized Root Mean Square Residual:

  SRMR                                           0.063

Parameter Estimates:

Error in if (categorical.flag) { : argument is of length zero

Restarting R session...

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8  
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] compiler_4.4.0    tools_4.4.0       foreign_0.8-86    rstudioapi_0.16.0
 [5] lavaan_0.6-17     Rcpp_1.0.12       Amelia_1.8.2      mnormt_2.1.1    
 [9] pbivnorm_0.6.0    stats4_4.4.0      semTools_0.5-6    quadprog_1.5-8  
semTools is now loaded via namespace after restarting R session....
> summary(out1)
   Length     Class      Mode
        1 lavaan.mi        S4
> library(semTools)
Loading required package: lavaan
This is lavaan 0.6-17
lavaan is FREE software! Please report any bugs.
 
###############################################################################
This is semTools 0.5-6
All users of R (or SEM) are invited to submit functions or ideas for functions.
###############################################################################
> summary(out1)
lavaanList (0.6-17) -- based on 20 datasets (20 converged)

Latent Variables:
                    est.ave
  visual =~                
    x1                1.000
    x2                0.556
    x3                0.728
  textual =~              
    x4                1.000
    x5                0.661
    x6                0.993
  speed =~                
    x7                1.000
    x8                1.176
    x9                0.901

Covariances:
                    est.ave
  visual ~~                
    textual           0.428
    speed             0.242
  textual ~~              
    speed             0.177

Variances:
                    est.ave
   .x1                0.549
   .x2                1.132
   .x3                0.846
   .x4                0.450
   .x5                0.272
   .x6                0.309
   .x7                0.768
   .x8                0.449
   .x9                0.634
    visual            0.809
    textual           0.901
    speed             0.415

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8  
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

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

other attached packages:
[1] semTools_0.5-6 lavaan_0.6-17

loaded via a namespace (and not attached):
 [1] compiler_4.4.0    tools_4.4.0       foreign_0.8-86    rstudioapi_0.16.0
 [5] Rcpp_1.0.12       Amelia_1.8.2      mnormt_2.1.1      pbivnorm_0.6.0  
 [9] stats4_4.4.0      quadprog_1.5-8  

> showMethods(summary) # when the lavaan.mi object is inhereted, the summary does not work correctly, when it is not inherited the parameter estimates in my summary fail 
Function: summary (package base)
object="ANY"
object="lavaan"
object="lavaan.mi"
    (inherited from: object="lavaanList")

object="lavaanList"
object="mle"

Terrence Jorgensen

unread,
Jun 24, 2024, 10:45:48 AM6/24/24
to lavaan
Error in if (categorical.flag) { : argument is of length zero

This error was fixed months ago.  It should be resolved after updating lavaan (0.6-18 is on CRAN).
 
This is what you mentioned reading (i.e., what NOT to do):

loaded via a namespace (and not attached):
 [1] compiler_4.4.0    tools_4.4.0       foreign_0.8-86    rstudioapi_0.16.0
 [5] lavaan_0.6-17     Rcpp_1.0.12       Amelia_1.8.2      mnormt_2.1.1    
 [9] pbivnorm_0.6.0    stats4_4.4.0      semTools_0.5-6    quadprog_1.5-8  
semTools is now loaded via namespace after restarting R session....
> summary(out1)
   Length     Class      Mode
        1 lavaan.mi        S4

FYI,  you can install the new lavaan.mi package (as well as development versions of lavaan and semTools):
 
remotes::install_github("yrosseel/lavaan") 
remotes::install_github("TDJorgensen/lavaan.mi") 
remotes::install_github("simsem/semTools/semTools")

I deprecated runMI() functionality from semTools, and the lavaan.mi package is now updated with many bug-fixes and new features. Read the README and NEWS files closely before proceeding, because other small changes have been made to the user interface.

https://github.com/TDJorgensen/lavaan.mi

https://github.com/TDJorgensen/lavaan.mi/blob/main/NEWS.md

I hope to send this to CRAN by the end of the month or early July.

Terrence D. Jorgensen    (he, him, his)
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
http://www.uva.nl/profile/t.d.jorgensen

Юлия Музыченко

unread,
Jun 27, 2024, 11:32:34 PM6/27/24
to lavaan
Hello,

I have a problem with the code which worked perfectly well a month ago. What is wrong? 

Thank you for advice,
Best regards,
Yulia

I need to rerun it and now:

> #### CFA. Sense of coherence #### > soc_model<-'SOC =~ soc1 + soc2 + soc3 + soc4 + soc5 + soc6 + soc7 + soc8 + soc9 + soc10 + soc11 + soc12 + soc13' > fit_soc <- cfa.mi(soc_model, data = imp, std.lv = TRUE, FUN = fitMeasures) Warning message: The runMI() function and lavaan.mi-class have been deprecated and will cease to be included in future versions of semTools. Support is still provided for analyzing lavaan.mi-class objects (e.g., compRelSEM() can estimate reliability using pooled results), which can now be created using the lavaan.mi package. The deprecated runMI() function now creates an object of class OLDlavaan.mi, which can be analyzed using the deprecated functions in semTools, like lavTestLRT.mi(), that have been updated and improved in the lavaan.mi package. Find more details help('semTools-deprecated) > summary(fit_soc, fit.measures = TRUE, test="D2") Error in .local(object, ...) : unused arguments (fit.measures = TRUE, test = "D2")


> sessionInfo() R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045) Matrix products: default locale: [1] LC_COLLATE=Russian_Russia.utf8 LC_CTYPE=Russian_Russia.utf8 [3] LC_MONETARY=Russian_Russia.utf8 LC_NUMERIC=C [5] LC_TIME=Russian_Russia.utf8 time zone: Australia/Brisbane tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] semTools_0.5-6.941 lavaan_0.6-18 loaded via a namespace (and not attached): [1] shape_1.4.6.1 rstudioapi_0.15.0 magrittr_2.0.3 jomo_2.7-6 [5] TH.data_1.1-2 estimability_1.4.1 nloptr_2.0.3 rmarkdown_2.25 [9] fs_1.6.3 vctrs_0.6.3 memoise_2.0.1 minqa_1.2.6 [13] base64enc_0.1-3 htmltools_0.5.6 usethis_2.2.2 curl_5.0.2 [17] broom_1.0.5 Formula_1.2-5 mitml_0.4-5 htmlwidgets_1.6.2 [21] desc_1.4.2 plyr_1.8.9 sandwich_3.1-0 emmeans_1.8.8 [25] zoo_1.8-12 cachem_1.0.8 igraph_2.0.3 iterators_1.0.14 [29] mime_0.12 lifecycle_1.0.3 pkgconfig_2.0.3 Matrix_1.6-1.1 [33] R6_2.5.1 fastmap_1.1.1 shiny_1.7.5 digest_0.6.33 [37] OpenMx_2.21.11 fdrtool_1.2.17 colorspace_2.1-0 ps_1.7.5 [41] rprojroot_2.0.3 pkgload_1.3.3 Hmisc_5.1-2 semPlot_1.1.6 [45] fansi_1.0.4 abind_1.4-5 compiler_4.3.1 remotes_2.4.2.1 [49] glasso_1.11 htmlTable_2.4.2 backports_1.4.1 carData_3.0-5 [53] psych_2.4.3 pkgbuild_1.4.2 pan_1.9 MASS_7.3-60 [57] sessioninfo_1.2.2 corpcor_1.6.10 gtools_3.9.5 tools_4.3.1 [61] pbivnorm_0.6.0 foreign_0.8-84 zip_2.3.0 httpuv_1.6.11 [65] nnet_7.3-19 glue_1.6.2 quadprog_1.5-8 callr_3.7.3 [69] nlme_3.1-162 promises_1.2.1 lisrelToR_0.3 grid_4.3.1 [73] checkmate_2.3.1 cluster_2.1.4 reshape2_1.4.4 generics_0.1.3 [77] gtable_0.3.4 tidyr_1.3.1 data.table_1.14.8 utf8_1.2.3 [81] sem_3.1-15 foreach_1.5.2 pillar_1.9.0 stringr_1.5.0 [85] rockchalk_1.8.157 later_1.3.1 splines_4.3.1 dplyr_1.1.3 [89] lattice_0.21-8 survival_3.5-5 kutils_1.73 tidyselect_1.2.0 [93] miniUI_0.1.1.1 pbapply_1.7-2 knitr_1.44 gridExtra_2.3 [97] stats4_4.3.1 xfun_0.40 qgraph_1.9.8 devtools_2.4.5 [101] arm_1.14-4 stringi_1.7.12 boot_1.3-28.1 evaluate_0.22 [105] codetools_0.2-19 mi_1.1 tibble_3.2.1 cli_3.6.1 [109] RcppParallel_5.1.7 rpart_4.1.19 xtable_1.8-4 munsell_0.5.0 [113] processx_3.8.2 Rcpp_1.0.11 coda_0.19-4.1 png_0.1-8 [117] XML_3.99-0.16.1 parallel_4.3.1 ellipsis_0.3.2 ggplot2_3.4.2 [121] prettyunits_1.2.0 jpeg_0.1-10 profvis_0.3.8 urlchecker_1.0.1 [125] glmnet_4.1-8 lme4_1.1-34 mvtnorm_1.2-3 scales_1.2.1 [129] openxlsx_4.2.5.2 purrr_1.0.2 crayon_1.5.2 rlang_1.1.1 [133] multcomp_1.4-25 mnormt_2.1.1 mice_3.16.0
вторник, 25 июня 2024 г. в 00:45:48 UTC+10, Terrence Jorgensen:

Юлия Музыченко

unread,
Jun 28, 2024, 1:05:14 AM6/28/24
to lavaan
I tried to force it to reinstall old versions of lavaan and semtools, now it got worse, now it doesn't compute the model at all and I can't fix it by reinstalling new versions of the packages:

> #### CFA. Sense of coherence #### > soc_model<-'SOC =~ soc1 + soc2 + soc3 + soc4 + soc5 + soc6 + soc7 + soc8 + soc9 + soc10 + soc11 + soc12 + soc13' > fit_soc <- cfa.mi(soc_model, data = imp, std.lv = TRUE, FUN = fitMeasures) Error in slot(value, what) : no slot of name "version" for this object of class "lavaanList" In addition: Warning message: The runMI() function and lavaan.mi-class have been deprecated and will cease to be included in future versions of semTools. Support is still provided for analyzing lavaan.mi-class objects (e.g., compRelSEM() can estimate reliability using pooled results), which can now be created using the lavaan.mi package. The deprecated runMI() function now creates an object of class OLDlavaan.mi, which can be analyzed using the deprecated functions in semTools, like lavTestLRT.mi(), that have been updated and improved in the lavaan.mi package. Find more details help('semTools-deprecated)

пятница, 28 июня 2024 г. в 13:32:34 UTC+10, Юлия Музыченко:

Terrence Jorgensen

unread,
Jul 5, 2024, 6:02:45 PM7/5/24
to lavaan
What is wrong? 

According to the deprecation message your copy/pasted into your post, the problem is that you are still trying to use runMI() in semTools, instead of running the analysis in the new lavaan.mi package. 

Юлия Музыченко

unread,
Jul 8, 2024, 2:14:45 PM7/8/24
to lav...@googlegroups.com

How can I fix it? Because in my understanding I use CFA.mi() function, and I believe it was not declared to be changed.


сб, 6 июл. 2024 г., 08:02 Terrence Jorgensen <tjorge...@gmail.com>:
What is wrong? 

According to the deprecation message your copy/pasted into your post, the problem is that you are still trying to use runMI() in semTools, instead of running the analysis in the new lavaan.mi package. 

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/24901502-89db-44b0-bba7-536c0334c090n%40googlegroups.com.

Terrence Jorgensen

unread,
Jul 10, 2024, 8:09:57 PM7/10/24
to lavaan

How can I fix it?

Use the lavaan.mi package. 

Because in my understanding I use CFA.mi() function, and I believe it was not declared to be changed.

It was changed.  The new one is in the lavaan.mi package.  The old one in semTools is outdated, and its output will no longer be supported.
Reply all
Reply to author
Forward
0 new messages