simsem / semTools

Useful tools for structural equation modeling
75 stars 36 forks source link

error in fitMeasures with lavaan.mi #43

Closed maugavilla closed 6 years ago

maugavilla commented 6 years ago

When using lavaan.mi with the latest semTools and lavaan the fitMeasures dont work. And the fit indices cannot be accessed with the previous anova method.

example from the help page of runMI

out1 <- cfa.mi(HS.model, data = HSMiss, m = 20, seed = 12345, miArgs = list(noms = "school"))

fitMeasures(out1) Error in gp.resid.lavaan.mi(Observed = object@SampleStatsList[useImps], : object 'N' not found

sessionInfo() R version 3.5.1 (2018-07-02) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

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] Amelia_1.7.5 semTools_0.5-1 lavaan_0.6-3

loaded via a namespace (and not attached): [1] MASS_7.3-50 compiler_3.5.1 parallel_3.5.1 tools_3.5.1 foreign_0.8-71 Rcpp_0.12.19 mnormt_1.5-5 pbivnorm_0.6.0 [9] stats4_3.5.1

TDJorgensen commented 6 years ago

fixed this bug, thanks for finding this. You can install the development version from github:

devtools::install_github("simsem/semTools/semTools")

To be consistent with lavaan, the anova() method no longer returns fit indices, and the D1 statistic has been moved to a separate lavTestWald.mi() function. Other updates are announced here:

https://github.com/simsem/semTools/wiki

OiverCheng commented 5 years ago

I have the same problem when using cfa.mi and fitMeasures(), like Error in gp.resid.lavaan.mi(Observed = object@SampleStatsList[useImps], : object 'N' not found.

But when I'm trying to use "devtools::install_github("simsem/semTools/semTools")", there are some other errors like:
Error : package 'lavaan' 0.6.3 was found, but >= 0.6.4 is required by 'semTools' ERROR: lazy loading failed for package 'semTools'

In R CMD INSTALL Error in i.p(...) : (converted from warning) installation of package ‘C:/Users/Princess/AppData/Local/Temp/RtmpoBawbM/file19f84966222f/semTools_0.5-1.916.tar.gz’ had non-zero exit status

But the latest version of lavaan is only 0.6.3, how can I solve that?

TDJorgensen commented 5 years ago

But the latest version of lavaan is only 0.6.3, how can I solve that?

By installing the latest development version of lavaan (a new function in semTools requires functionality unavailable in the CRAN version of lavaan).

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

OiverCheng commented 5 years ago

Problem solved, thank you so much!

dgnhatun commented 5 years ago

I am having the same error message for "srmr" fit measure. Without the srmr code I do not have any error message.

My codes:

imputation

hway_imp<-mice(data, m = 5, seed = 12435) mice.imp5 <- NULL for(i in 1:5) mice.imp5[[i]] <- complete(hway_imp, action=i, inc=FALSE)

model and fit measures

latent1 <- 'Neigh =~ var1+ var2 + var3 + var4' out1 <- runMI(latent1, data=mice.imp5, fun="cfa", meanstructure = TRUE) summary(out1) fitMeasures(out1, c("chisq", "df", "pvalue", "cfi", "tli", "rmsea", "srmr"))

error message

fitMeasures(out1, c("chisq", "df", "pvalue", "cfi", "tli", "rmsea", "srmr")) Error in gp.resid.lavaan.mi(Observed = object@SampleStatsList[useImps], : object 'N' not found BUT,

When I run "runMI" with group = "gender", I can see SRMR result without any error message (I am also not sure if it is okay to use group option this way).

latent1 <- 'Neigh =~ var1+ var2 + var3 + var4' out1 <- runMI(latent1, data=mice.imp5, fun="cfa", meanstructure = TRUE, group = "gender") summary(out1) fitMeasures(out1, c("chisq", "df", "pvalue", "cfi", "tli", "rmsea", "srmr"))

results

fitMeasures(out1, c("chisq", "df", "pvalue", "cfi", "tli", "rmsea", "srmr"))

chisq df pvalue baseline.chisq baseline.df baseline.pvalue cfi tli rmsea
4.792 4.000 0.309 993.641 12.000 0.000 0.999 0.998 0.020 rmsea.ci.lower rmsea.ci.upper rmsea.pvalue srmr 0.000 0.073 0.771 0.010

How can I solve this error problem? Thanks

TDJorgensen commented 5 years ago

lavaan 0.6-4 is now available on CRAN, but you still need the latest development version of semTools, in which this error was long ago resolved.

devtools::install_github("simsem/semTools/semTools")
dgnhatun commented 5 years ago

Thanks for your response, but both R and Rstudio show this error message:

devtools::install_github("simsem/semTools/semTools") Downloading GitHub repo simsem/semTools@master Error: Failed to install 'semTools' from GitHub: invalid octal digit

TDJorgensen commented 5 years ago

Are you sure you have lavaan >= 0.6-4, and R >= 3.4? What is your sessionInfo() output?

dgnhatun commented 5 years ago

sessionInfo() R version 3.6.1 (2019-07-05)

Matrix products: default Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding

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

other attached packages: [1] foreign_0.8-71 lavaan.survey_1.1.3.1 semTools_0.5-1 lavaan_0.6-4 mitools_2.4 Amelia_1.7.5 Rcpp_1.0.1
[8] mice_3.6.0 lattice_0.20-38 survey_3.36 survival_2.44-1.1 Matrix_1.2-17

loaded via a namespace (and not attached): [1] tidyselect_0.2.5 remotes_2.1.0 purrr_0.3.2 splines_3.6.1 generics_0.0.2 testthat_2.1.1 stats4_3.6.1 usethis_1.5.1 pan_1.6
[10] rlang_0.4.0 pkgbuild_1.0.3 jomo_2.6-8 pillar_1.4.2 nloptr_1.2.1 glue_1.3.1 withr_2.1.2 DBI_1.0.0 sessioninfo_1.1.1 [19] devtools_2.1.0 memoise_1.1.0 callr_3.3.0 ps_1.3.0 parallel_3.6.1 broom_0.5.2 backports_1.1.4 desc_1.2.0 pkgload_1.0.2
[28] fs_1.3.1 lme4_1.1-21 mnormt_1.5-5 digest_0.6.20 processx_3.4.0 dplyr_0.8.3 rprojroot_1.3-2 cli_1.1.0 tools_3.6.1
[37] magrittr_1.5 tibble_2.1.3 pbivnorm_0.6.0 crayon_1.3.4 tidyr_0.8.3 pkgconfig_2.0.2 MASS_7.3-51.4 prettyunits_1.0.2 assertthat_0.2.1 [46] minqa_1.2.4 rstudioapi_0.10 mitml_0.3-7 R6_2.4.0 boot_1.3-22 rpart_4.1-15 nnet_7.3-12 nlme_3.1-140 compiler_3.6.1

dgnhatun commented 5 years ago

Thanks for your response, but both R and Rstudio show this error message:

devtools::install_github("simsem/semTools/semTools") Downloading GitHub repo simsem/semTools@master Error: Failed to install 'semTools' from GitHub: invalid octal digit

Is there any other way to download this package?

TDJorgensen commented 5 years ago

invalid octal digit

This was a typo in my DESCRIPTION file, that is now fixed.

dgnhatun commented 5 years ago

Thanks alot for your help. It worked with the code below.

install.packages("Rtools") install.packages(c('devtools','curl')) library('devtools') devtools::install_github("simsem/semTools/semTools")