yrosseel / lavaan

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

lav_fit_cfi_lavobject() error following lav_fit_catml_dwls() error #279

Closed TDJorgensen closed 1 year ago

TDJorgensen commented 1 year ago

Hi Yves, This issue came up in a simsem application: simsem/simsem#82

The user is fitting an empirically underidentified model (essentially a bifactor model with 2 correlated methods, although their syntax indicates they might not recognize it as such), and sim() fails after a replication appears to have lavInspect(fit, "converged"), yet fitMeasures() unexpectedly fails. The dump()ed data and syntax are in this reprex (a .txt file with R syntax, because GitHub won't upload a .R file). I tracked down the error to

https://github.com/yrosseel/lavaan/blob/master/R/lav_fit_cfi.R#L439

At this point, you attempt to extract out$XX3.null, even if out (on Line 350) is a try-error. Perhaps you can simply assign XX3.null and c.hat3.null as NA when you conditionally assign the other values on Line 353? Or add the same if (inherits(out, "try-error")) check on Lines 439-440?

Granted, the results from this replication should probably be ignored in the full simulation, but by default simsem should notice the lack of SEs and exclude this replication from summaries, unless the user specifies otherwise.

Thanks!

yrosseel commented 1 year ago

Indeed. Thanks for tracking this down. Fixed now in the github version.