Dear Lavaan group,
Help is needed.
I carry out a CFA with categorical data using a data with missing values. My approach, however, seems to run into issues that previous posts do not seem to address. Following the previous suggestions, I prepared the analysis in R as follows:
install.packages("devtools")
devtools::install_github("simsem/semTools/semTools")
I also downloaded and installed Rtools 3.5 to make sure all is in place. So I should have amongst others the development version of lavaan in place. In order to generate the imputations, I have been using MICE (EXCLUDE is a set of variables I did not want to use for the imputations):
PREDICTORMATRIX <- quickpred(BASELINE, exclude = EXCLUDE, mincor = 0.2, method = "kendall")
IMPUTE <- mice(BASELINE, predictorMatrix = PREDICTORMATRIX, m = 5)
I want to test various models all looped through the cfa command. One of the simpler models is of the form
MODELS$M1 <- '
C_Mot =~ 1* C_AB2+ C_AB3+ C_AB4+ C_AB5 + C_AB6 + C_AB8 + C_AB_PO2
E_Motivation =~ 1*E_AB2+ E_AB3+ E_AB4+ E_AB5 + E_AB6 + E_AB8
K_Motivation =~ 1* K_AB2+ K_AB3+ K_AB4+ K_AB5 + K_AB6 + K_AB8
M_Motivation =~ 1* M_AB2+ M_AB3+ M_AB4+ M_AB5 + M_AB6 + M_AB8 + M_AB_PO2'
The different models are saved in the list called MODELS. Since the I have multiply imputed data sets, I use runIM. In the loop below, all analysis output will be saved in the list called fits. VARIABLES specifies the categorical variables in the model (e.g. C_AB2).
for (MOD in 1: length(MODELS)) {
fits$fit <- runMI(MODELS[[MOD]],
data=IMPUTE,
fun="cfa",
ordered= VARIABLES)
names(fits)[length(fits)] <- paste0("M",MOD)
}
Without imputations, this general set up (e.g. loop) seems to have worked fine. With the imputations, however, I nw run into problems. The loop spits out the following error message:
"D3" only available using maximum likelihood estimation. Changed test to "D2".
Robust corrections are made by pooling the naive chi-squared statistic across 5 imputations for which the model converged, then applying the average (across imputations) scaling factor and shift parameter to that pooled value.
To instead pool the robust test statistics, set test = "D2" and pool.robust = TRUE.
and
Error in getMethod("resid", "lavaan.mi") :
no method found for function 'resid' and signature lavaan.mi
In addition: Warning messages:
1: In pchisq(X2, DF, ncp = N * DF * 0.05^2/nG, lower.tail = FALSE) :
full precision may not have been achieved in 'pnchisq'
2: In pchisq(X2.sc, DF, ncp = N * DF * 0.05^2/nG, lower.tail = FALSE) :
full precision may not have been achieved in 'pnchisq'
The first error message has continued to emerge for seevral iterations of my attempts to make it work. In fact, it made me look up solutions in this group amongst others. The second one is rather new and I could not find anything about it. Any help much appreciated. I also include the session info:
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] mice_3.13.0 robustHD_0.6.1 perry_0.2.0 robustbase_0.93-6 ggplot2_3.3.0
[6] semTools_0.5-4.904 lavaan_0.6-8 psych_1.9.12.31 moments_0.14 readxl_1.3.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 lattice_0.20-38 tidyr_1.0.3 prettyunits_1.1.1 ps_1.3.3
[6] assertthat_0.2.1 rprojroot_1.3-2 R6_2.4.1 cellranger_1.1.0 backports_1.1.6
[11] stats4_3.6.2 pillar_1.4.4 rlang_0.4.10 curl_4.3 rstudioapi_0.11
[16] callr_3.5.1 pbivnorm_0.6.0 desc_1.2.0 devtools_2.3.2 munsell_0.5.0
[21] broom_0.5.6 compiler_3.6.2 pkgconfig_2.0.3 mnormt_2.0.2 pkgbuild_1.2.0
[26] tmvnsim_1.0-2 nnet_7.3-12 tidyselect_1.0.0 tibble_3.0.1 fansi_0.4.1
[31] crayon_1.3.4 dplyr_0.8.5 withr_2.4.1 MASS_7.3-51.5 grid_3.6.2
[36] nlme_3.1-142 gtable_0.3.0 lifecycle_0.2.0 magrittr_1.5 scales_1.1.1
[41] cli_2.0.2 cachem_1.0.1 fs_1.5.0 remotes_2.2.0 testthat_2.3.2
[46] ellipsis_0.3.1 generics_0.0.2 vctrs_0.2.4 tools_3.6.2 glue_1.4.0
[51] DEoptimR_1.0-8 purrr_0.3.4 processx_3.4.5 pkgload_1.1.0 fastmap_1.1.0
[56] colorspace_1.4-1 sessioninfo_1.1.1 memoise_2.0.0 usethis_2.0.0
Thanks,
Dom