yrosseel / lavaan

an R package for structural equation modeling and more
http://lavaan.org
412 stars 99 forks source link

fitMeasures() don't show fits with missing = "ML" for CFA #276

Open SiPineau opened 1 year ago

SiPineau commented 1 year ago

Hello,

I run a CFA on a large model. As missing data are MCAR, I used missing = "ML". My model run correctly but the function fitMeasures() run indefinitely without being able to show fits. If I try to run the model without missing = "ML", fitMeasures() is able to print fits (but there are variance-covariance problems in the model). It's strange because I did the model several months ago and it work fine, and I have other similar models where fitMeasures() run correctly.

Do you have any suggestions to fix this issue ? There is the model below (N = 846) :

CFAVISAINVARfree <-'
Engagement_T1 =~ VISA01_T1 + VISA02_T1 + VISA03_T1 + VISA04_T1 ID a engagement_T1 =~ VISA06_T1 + VISA07_T1 + VISA09_T1 Flex engagement_T1 =~ VISA11_T1 + VISA12_T1 + VISA13_T1 + VISA14_T1 Doutes_T1 =~ VISA16_T1 + VISA18_T1 + VISA19_T1 + VISA20_T1 + VISA15_T1 Expl surface_T1 =~ VISA21_T1 + VISA22_T1 + VISA23_T1 + VISA24_T1 + VISA25_T1 Expl prof_T1 =~ VISA26_T1 + VISA27_T1 + VISA28_T1 + VISA29_T1 + VISA30_T1 + VISA05_T1 VISA27_T1 ~~ VISA28_T1 VISA02_T1 ~~ VISA03_T1

Engagement_T2 =~ VISA01_T2 + VISA02_T2 + VISA03_T2 + VISA04_T2
ID a engagement_T2 =~ VISA06_T2 + VISA07_T2 + VISA09_T2
Flex engagement_T2 =~ VISA11_T2 + VISA12_T2 + VISA13_T2 + VISA14_T2
Doutes_T2 =~ VISA16_T2 + VISA18_T2 + VISA19_T2 + VISA20_T2  + VISA15_T2
Expl surface_T2 =~ VISA21_T2 + VISA22_T2 + VISA23_T2 + VISA24_T2 + VISA25_T2
Expl prof_T2 =~ VISA26_T2 + VISA27_T2 + VISA28_T2 + VISA29_T2 + VISA30_T2 + VISA05_T2
VISA27_T2   ~~  VISA28_T2
VISA02_T2   ~~  VISA03_T2

Engagement_T3 =~ VISA01_T3 + VISA02_T3 + VISA03_T3 + VISA04_T3
ID a engagement_T3 =~ VISA06_T3 + VISA07_T3 + VISA09_T3
Flex engagement_T3 =~ VISA11_T3 + VISA12_T3 + VISA13_T3 + VISA14_T3
Doutes_T3 =~ VISA16_T3 + VISA18_T3 + VISA19_T3 + VISA20_T3  + VISA15_T3
Expl surface_T3 =~ VISA21_T3 + VISA22_T3 + VISA23_T3 + VISA24_T3 + VISA25_T3
Expl prof_T3 =~ VISA26_T3 + VISA27_T3 + VISA28_T3 + VISA29_T3 + VISA30_T3 + VISA05_T3
VISA27_T3   ~~  VISA28_T3
VISA02_T3   ~~  VISA03_T3

Engagement_T4 =~ VISA01_T4 + VISA02_T4 + VISA03_T4 + VISA04_T4
ID a engagement_T4 =~ VISA06_T4 + VISA07_T4 + VISA09_T4
Flex engagement_T4 =~ VISA11_T4 + VISA12_T4 + VISA13_T4 + VISA14_T4
Doutes_T4 =~ VISA16_T4 + VISA18_T4 + VISA19_T4 + VISA20_T4  + VISA15_T4
Expl surface_T4 =~ VISA21_T4 + VISA22_T4 + VISA23_T4 + VISA24_T4 + VISA25_T4
Expl prof_T4 =~ VISA26_T4 + VISA27_T4 + VISA28_T4 + VISA29_T4 + VISA30_T4 + VISA05_T4
VISA27_T4   ~~  VISA28_T4
VISA02_T4   ~~  VISA03_T4

Engagement =~ Engagement_T1 + Engagement_T2 + Engagement_T3 + Engagement_T4 IDaengagement =~ IDaengagement_T1 + IDaengagement_T2 + IDaengagement_T3 + IDaengagement_T4 Flexengagement =~ Flexengagement_T1 + Flexengagement_T2 + Flexengagement_T3 + Flexengagement_T4 Doutes =~ Doutes_T1 + Doutes_T2 + Doutes_T3 + Doutes_T4 Explsurface =~ Explsurface_T1 + Explsurface_T2 + Explsurface_T3 + Explsurface_T4 Explprof =~ Explprof_T1 + Explprof_T2 + Explprof_T3 + Explprof_T4

Engagement ~~ IDaengagement Engagement ~~ Flexengagement Engagement ~~ Doutes Engagement ~~ Explsurface Engagement ~~ Explprof

IDaengagement ~~ Flexengagement IDaengagement ~~ Doutes IDaengagement ~~ Explsurface IDaengagement ~~ Explprof

Flexengagement ~~ Doutes Flexengagement ~~ Explsurface Flexengagement ~~ Explprof

Doutes ~~ Explsurface Doutes ~~ Explprof

Explsurface ~~ Explprof

F01 =~ 1VISA01_T1 + 1VISA01_T2 + 1VISA01_T3 + 1VISA01_T4 F02 =~ 1VISA02_T1 + 1VISA02_T2 + 1VISA02_T3 + 1VISA02_T4 F03 =~ 1VISA03_T1 + 1VISA03_T2 + 1VISA03_T3 + 1VISA03_T4 F04 =~ 1VISA04_T1 + 1VISA04_T2 + 1VISA04_T3 + 1VISA04_T4 F05 =~ 1VISA05_T1 + 1VISA05_T2 + 1VISA05_T3 + 1VISA05_T4 F06 =~ 1VISA06_T1 + 1VISA06_T2 + 1VISA06_T3 + 1VISA06_T4 F07 =~ 1VISA07_T1 + 1VISA07_T2 + 1VISA07_T3 + 1VISA07_T4 F09 =~ 1VISA09_T1 + 1VISA09_T2 + 1VISA09_T3 + 1VISA09_T4 F11 =~ 1VISA11_T1 + 1VISA11_T2 + 1VISA11_T3 + 1VISA11_T4 F12 =~ 1VISA12_T1 + 1VISA12_T2 + 1VISA12_T3 + 1VISA12_T4 F13 =~ 1VISA13_T1 + 1VISA13_T2 + 1VISA13_T3 + 1VISA13_T4 F14 =~ 1VISA14_T1 + 1VISA14_T2 + 1VISA14_T3 + 1VISA14_T4 F15 =~ 1VISA15_T1 + 1VISA15_T2 + 1VISA15_T3 + 1VISA15_T4 F16 =~ 1VISA16_T1 + 1VISA16_T2 + 1VISA16_T3 + 1VISA16_T4 F18 =~ 1VISA18_T1 + 1VISA18_T2 + 1VISA18_T3 + 1VISA18_T4 F19 =~ 1VISA19_T1 + 1VISA19_T2 + 1VISA19_T3 + 1VISA19_T4 F20 =~ 1VISA20_T1 + 1VISA20_T2 + 1VISA20_T3 + 1VISA20_T4 F21 =~ 1VISA21_T1 + 1VISA21_T2 + 1VISA21_T3 + 1VISA21_T4 F22 =~ 1VISA22_T1 + 1VISA22_T2 + 1VISA22_T3 + 1VISA22_T4 F23 =~ 1VISA23_T1 + 1VISA23_T2 + 1VISA23_T3 + 1VISA23_T4 F24 =~ 1VISA24_T1 + 1VISA24_T2 + 1VISA24_T3 + 1VISA24_T4 F25 =~ 1VISA25_T1 + 1VISA25_T2 + 1VISA25_T3 + 1VISA25_T4 F26 =~ 1VISA26_T1 + 1VISA26_T2 + 1VISA26_T3 + 1VISA26_T4 F27 =~ 1VISA27_T1 + 1VISA27_T2 + 1VISA27_T3 + 1VISA27_T4 F28 =~ 1VISA28_T1 + 1VISA28_T2 + 1VISA28_T3 + 1VISA28_T4 F29 =~ 1VISA29_T1 + 1VISA29_T2 + 1VISA29_T3 + 1VISA29_T4 F30 =~ 1VISA30_T1 + 1VISA30_T2 + 1VISA30_T3 + 1VISA30_T4

F02 ~~ F03 F27 ~~ F28 '

fitvisainvar_free <- cfa(CFAVISAINVARfree, datavisalongi[c(2:121)], missing = "ML") fitMeasures(fitvisainvar_free, c("cfi", "rmsea", "srmr"))

yrosseel commented 1 year ago

It takes forever, but it should work eventually. Nevertheless, I will see if I can either speed things up, or if the robust fit measures can be shut-off when the model is rather large.

This is all related to the new 'robust' CFI and RMSEA fit measures that were introduced in lavaan 0.6-13 for the specific setting when missing = "ml". These new fit measures are clearly superior to the 'old' versions, but there is a huge computational cost... This is the reference:

Zhang, X., & Savalei, V. (2023). New computations for RMSEA and CFI following FIML and TS estimation with missing data. Psychological Methods, 28(2), 263–283. https://doi.org/10.1037/met0000445

SiPineau commented 1 year ago

Thank you for your answer and the reference !

yrosseel commented 11 months ago

This is still not fixed, but in the github version of lavaan, you can at least 'switch off' the computation of the robust rmsea/cfi fit measures when it takes forever. As follows:

fitMeasures(fit, fm.args = list(robust = FALSE))

or

summary(fit, fit.measures = TRUE, fm.args = list(robust = FALSE))