Error summarizing imputed model from semTools::runMI

798 views
Skip to first unread message

nthr...@gmail.com

unread,
Jun 24, 2021, 2:32:03 PM6/24/21
to lavaan
The documentation for `runMI` (line 107) suggests that using lavaan::summary() on the output of runMI can extract fit measures and, ideally, confidence intervals as well. However, when I try that, an error says that neither "fit.measures" nor "ci" are valid arguments to the summary function. Minimal reprex below:

set.seed(42)

# Print package versions----------------------------------------
sapply(c("semTools", "lavaan", "mice"),
       packageVersion, 
       simplify = FALSE)
#> $semTools
#> [1] '0.5.4'
#> 
#> $lavaan
#> [1] '0.6.8'
#> 
#> $mice
#> [1] '3.13.0'

# Generate data with missing values-----------------------------
x <- rnorm(100)
y <- .5*x + rnorm(100)
d <- data.frame(x, y)
d$x[sample(100, 20)] <- as.numeric(NA)
d$y[sample(100, 20)] <- as.numeric(NA)
head(d)
#>            x           y
#> 1  1.3709584  1.88644460
#> 2 -0.5646982          NA
#> 3  0.3631284          NA
#> 4  0.6328626  2.16491320
#> 5         NA -0.46463925
#> 6 -0.1061245  0.05245155

# Run simple regression with multiple imputation----------------
mod <- semTools::runMI(
  'y ~ x', 
  data = d,
  m = 20, 
  miPackage = "mice",
  fun = "sem"
)
#> Loading required namespace: mice

# Try to summarize output including confidence intervals--------
lavaan::summary(mod, fit.measures = TRUE)
#> Error in .local(object, ...): unused argument (fit.measures = TRUE)
lavaan::summary(mod, ci = TRUE)
#> Error in .local(object, ...): unused argument (ci = TRUE)

Terrence Jorgensen

unread,
Jul 8, 2021, 4:08:18 AM7/8/21
to lavaan
The documentation for `runMI` (line 107) suggests that using lavaan::summary()

The documentation in no way suggests using one of lavaan's summary() methods.  It just shows the use of the generic summary() function,  which will find the appropriate method for lavaan.mi (not lavaan) objects.
 
an error says that neither "fit.measures" nor "ci" are valid arguments to the summary function

The lavaan package also has a summary() method for lavaanList objects, from which lavaan.mi inherits.  The summary() method for lavaanList objects does not have those arguments.  The one in the semTools package for lavaan.mi objects does.

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

 

nthr...@gmail.com

unread,
Jul 8, 2021, 11:35:00 AM7/8/21
to lavaan
Got it. So changing the summary functions from lavaan to the generic summary() does not work for me:

summary(mod, fit.measures = TRUE)
#>    Length     Class      Mode 
#>         1 lavaan.mi        S4
summary(mod, ci = TRUE)
#>    Length     Class      Mode 
#>         1 lavaan.mi        S4

Nor does calling the internal semTools summary function for lavaan.mi objects:

semTools:::summary.lavaan.mi(mod, fit.measures = TRUE)
#> Error in getMethod("coef", "lavaan.mi"): no method found for function 'coef' and signature lavaan.mi
semTools:::summary.lavaan.mi(mod, ci = TRUE)
#> Error in getMethod("coef", "lavaan.mi"): no method found for function 'coef' and signature lavaan.mi

However, loading the semTools package explicitly with library(semTools) does work, albeit with an error when trying to calculate fit.measures:

summary(mod, 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.
#> Error in D3.LRT(object, h1 = h1, useImps = useImps, asymptotic = asymptotic, : D3 test statistic could not be calculated. Try the D2 pooling method.

summary(mod, ci = 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.
#> 
#> Parameter Estimates:
#> 
#>   Standard errors                             Standard
#>   Information                                 Expected
#>   Information saturated (h1) model          Structured
#> 
#> Regressions:
#>                    Estimate  Std.Err  t-value       df  P(>|t|) ci.lower
#>   y ~                                                                   
#>     x                 0.385    0.125    3.073   84.009    0.003    0.136
#>  ci.upper
#>          
#>     0.635
#> 
#> Variances:
#>                    Estimate  Std.Err  t-value       df  P(>|t|) ci.lower
#>    .y                 0.911    0.167    5.452  209.224    0.000    0.581
#>  ci.upper
#>     1.240

Terrence Jorgensen

unread,
Jul 10, 2021, 7:11:47 AM7/10/21
to lavaan
loading the semTools package explicitly with library(semTools) does work

That would be the usual way of getting a lavaan.mi object and accessing its methods.
 
an error when trying to calculate fit.measures:

#> Error in D3.LRT(object, h1 = h1, useImps = useImps, asymptotic = asymptotic, : D3 test statistic could not be calculated. Try the D2 pooling method.

Did you try test = "D2"?  Sometimes the D3 cannot be calculated.

nthr...@gmail.com

unread,
Jul 15, 2021, 11:57:19 AM7/15/21
to lavaan
Yes, the test = "D2" argument works in the summary function and in the fitMeasures function when semTools is explicitly loaded. Thanks!

paul.tho...@gmail.com

unread,
Feb 23, 2024, 6:54:55 AM2/23/24
to lavaan
I'm having the same issue after updating R, Rstudio, and packages lavaan, semTools. Seems fine if not asking for fit.measures? 

> library(semTools) > fitmodel3b <- sem.mi(model3, data=imp,ordered = c("Gender","autismstatus"),miPackage = "mice") > summary(fitmodel3b, fit.measures=TRUE) Error in .local(object, ...) : unused argument (fit.measures = TRUE) > semTools:::summary(fitmodel3b, fit.measures=TRUE) Error: object 'summary' not found > summary(fitmodel3b) lavaanList (0.6-15) -- based on 10 datasets (10 converged)

> print(sessionInfo()) R version 4.3.2 (2023-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045) Matrix products: default locale: [1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8 time zone: Europe/London tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] mice_3.15.0 MissMech_1.0.3 naniar_1.0.0 haven_2.5.2 broom_1.0.4 semPlot_1.1.6 sjPlot_2.8.14 lubridate_1.9.2 [9] forcats_1.0.0 stringr_1.5.0 dplyr_1.1.2 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0 tibble_3.2.1 ggplot2_3.4.2 [17] tidyverse_2.0.0 psych_2.3.3 readxl_1.4.2 semTools_0.5-6 lavaan_0.6-15

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

unread,
May 8, 2024, 3:42:54 PM5/8/24
to lavaan
Dear Professor  Terrence D. Jorgensen,

Thank you for all you are doing for researchers!

I have a problem with the generic function summary() that you mentioned here as a solution to get one solution for imputed data used in SEM.
I have a multiple imputed dataset. I saved it as a laavan.mi object:
> class(sem.unordered) [1] "lavaan.mi" attr(,"package") [1] "semTools"

When I run summary() function it only gives me estimates, no p-values, no model fit indices.
> summary(sem.unordered) lavaanList (0.6-17) -- based on 20 datasets (20 converged) Latent Variables: est.ave ES =~ es1 1.000 es2 1.004
*******

If I try using some additional options for summary it gives me errors:

> summary(sem.unordered, standardized = TRUE, fit.measures = TRUE,ci=TRUE) Error in .local(object, ...) : unused arguments (standardized = TRUE, fit.measures = TRUE, ci = TRUE)
> summary(sem.unordered, fit.measures = TRUE) Error in .local(object, ...) : unused argument (fit.measures = TRUE) > summary(sem.unordered,fit.measures = TRUE, test="D2") Error in .local(object, ...) : unused arguments (fit.measures = TRUE, test = "D2") What can I do to get scandalized path coefficients with p-values and model fit indices?


Best Regards,
Yulia
четверг, 8 июля 2021 г. в 11:08:18 UTC+3, Terrence Jorgensen:

Yago Luksevicius de Moraes

unread,
May 10, 2024, 4:30:02 PM5/10/24
to lavaan

Hi, Yulia,

I have no experience with multiple imputed datasets, but I’ve seen the error

Error in .local(object, ...) : unused arguments (standardized = TRUE, fit.measures = TRUE, ci = TRUE)

when R tries to use the wrong summary function. Have you tried running lavaan::summary(sem.unordered, standardized = TRUE, fit.measures = TRUE,ci=TRUE)?

Best,
Yago

Reply all
Reply to author
Forward
0 new messages