simsem / semTools

Useful tools for structural equation modeling
74 stars 35 forks source link

summary() does not accept arguments for lavaan.mi #104

Closed martscht closed 2 years ago

martscht commented 2 years ago

Running the example code provided with 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"))

## ... or impute missing data first
library(Amelia)
set.seed(12345)
HS.amelia <- amelia(HSMiss, m = 20, noms = "school", p2s = FALSE)
imps <- HS.amelia$imputations
out2 <- cfa.mi(HS.model, data = imps)

## same results (using the same seed results in the same imputations)
cbind(impute.within = coef(out1), impute.first = coef(out2))

summary(out1, fit.measures = TRUE)
summary(out1, ci = FALSE, fmi = TRUE, output = "data.frame")
summary(out1, ci = FALSE, stand = TRUE, rsq = TRUE)`

produces to following errors:

> summary(out1, fit.measures = TRUE)
Error in .local(object, ...) : unused argument (fit.measures = TRUE)
> summary(out1, ci = FALSE, fmi = TRUE, output = "data.frame")
Error in .local(object, ...) : 
  unused arguments (ci = FALSE, fmi = TRUE, output = "data.frame")
> summary(out1, ci = FALSE, stand = TRUE, rsq = TRUE)
Error in .local(object, ...) : 
  unused arguments (ci = FALSE, stand = TRUE, rsq = TRUE)

indicating that there is a problem with the method for lavaan.mi objects. Tested on R 4.1.1, lavaan 0.6-9, and semTools 0.5-5.912 as well as 0.5-5

TDJorgensen commented 2 years ago

sessionInfo() output? If VGAM is loaded, there is a known interference that should be resolved in his next version. Perhaps other packages interfere with the path too, but haven't seen a reprex verifying it.

martscht commented 2 years ago

Thanks, though I do not have VGAM installed the problem appeared. However, I have since update my packages and the problem vanished, so I cannot say which other package it may have been, causing the interference.

ivmcphail commented 9 months ago

Hi, Terrence.

I have run into the above noted error as well. The 'cfa.mi' code I run is:

analysis.dwlsmv <- cfa.mi( mod, data = implist, ordered = c("cis4", "cis5", "cis7", "cis9", "cis10", "cis11", "cis12", "cis14", "cis15", "cis16","cis17","cis19","cis21","cis24","cis26","cis27","cis28","cis29","cis30", "cis33","cis34","cis36","cis40","cis6"), parameterization = "delta", estimator = "wlsmv")

summary(analysis.dwlsmv, se = TRUE, ci = TRUE, level = 0.95, standardized = TRUE, rsquare = TRUE)

Which throws out the error:

Error in .local(object, ...) : unused arguments (se = TRUE, ci = TRUE, level = 0.95, standardized = TRUE, rsquare = TRUE)

This code was working fine just a few days ago, after not working for a number days. I actually think having both lavaan.mi and semTools installed at the same time is the problem, even if one package is not loaded while the other one is loaded.

For instance, here is my sessionInfo() when the above error was being given:

R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale: [1] LC_COLLATE=English_Canada.utf8 LC_CTYPE=English_Canada.utf8 LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C
[5] LC_TIME=English_Canada.utf8

time zone: America/Edmonton tzcode source: internal

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

other attached packages: [1] lavaan.mi_0.1-0.0003 xlsx_0.6.5 lavaan_0.6-16 mitml_0.4-5

loaded via a namespace (and not attached): [1] xlsxjars_0.6.1 utf8_1.2.3 generics_0.1.3 tidyr_1.3.0 shape_1.4.6 lattice_0.21-8 lme4_1.1-34
[8] magrittr_2.0.3 grid_4.3.1 iterators_1.0.14 mice_3.16.0 foreach_1.5.2 jomo_2.7-6 Matrix_1.5-4.1
[15] glmnet_4.1-8 nnet_7.3-19 backports_1.4.1 survival_3.5-5 purrr_1.0.2 fansi_1.0.4 pbivnorm_0.6.0
[22] codetools_0.2-19 mnormt_2.1.1 cli_3.6.1 rlang_1.1.1 splines_4.3.1 remotes_2.4.2.1 pan_1.9
[29] parallel_4.3.1 tools_4.3.1 nloptr_2.0.3 minqa_1.2.5 dplyr_1.1.3 boot_1.3-28.1 broom_1.0.5
[36] rpart_4.1.19 vctrs_0.6.3 R6_2.5.1 stats4_4.3.1 lifecycle_1.0.3 MASS_7.3-60 pkgconfig_2.0.3 [43] rJava_1.0-6 pillar_1.9.0 glue_1.6.2 Rcpp_1.0.11 tibble_3.2.1 tidyselect_1.2.0 nlme_3.1-162
[50] compiler_4.3.1 quadprog_1.5-8

Now, I run:

remove.packages("lavaan.mi")

And rerun

summary(analysis.dwlsmv, se = TRUE, ci = TRUE, level = 0.95, standardized = TRUE, rsquare = TRUE)

And the summary() function runs just fine. I tried running sessionInfo() again, to show you that nothing changed other than uninstalling lavaan.mi, but got the following error:

Error in x$Priority : $ operator is invalid for atomic vectors In addition: Warning message: In FUN(X[[i]], ...) : DESCRIPTION file of package 'lavaan.mi' is missing or broken

But the only thing that changed from getting the error about unused arguments in summary() and it running fine was uninstalling lavaan.mi.

I'm not a programmer or a coder, so I don't know if any of this will help. But this error has been causing me headaches this past week, so hopefully something here will be helpful for you.

Ian.