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....