melissagwolf / dynamic

Dynamic Fit Index Cutoffs For Latent Variable Models
GNU Affero General Public License v3.0
15 stars 2 forks source link

Give informative error if accidentally providing under-identified factor with two loadings #14

Open sda030 opened 9 months ago

sda030 commented 9 months ago

I was looping across some constructs using cfaOne and forgot that I had a construct with only two items in there. Resulted in the following error and long list of warnings, which I think could be handled a bit better up-front.

dynamic::cfaOne(n = 477, model = "F =~ 0.955*S_227_67 + 0.672*S_227_70", 
                plot = FALSE, manual = TRUE)
#> Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING:
#>     Could not compute standard errors! The information matrix could
#>     not be inverted. This may be a symptom that the model is not
#>     identified.

#> Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING:
#>     Could not compute standard errors! The information matrix could
#>     not be inverted. This may be a symptom that the model is not
#>     identified.

#> Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING:
#>     Could not compute standard errors! The information matrix could
#>     not be inverted. This may be a symptom that the model is not
#>     identified.

# I have cut off about 497 similar warnings to save space.

#> Error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `dplyr::summarise()`:
#> ℹ In argument: `CFI_M = stats::quantile(CFI_M, c(0.95, 0.9))`.
#> Caused by error in `quantile.default()`:
#> ! missing values and NaN's not allowed if 'na.rm' is FALSE
#> Backtrace:
#>      ▆
#>   1. ├─dynamic::cfaOne(...)
#>   2. │ └─purrr::map(...)
#>   3. │   └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>   4. │     ├─purrr:::with_indexed_errors(...)
#>   5. │     │ └─base::withCallingHandlers(...)
#>   6. │     ├─purrr:::call_with_cleanup(...)
#>   7. │     └─dynamic (local) .f(.x[[i]], ...)
#>   8. │       ├─dplyr::summarise(...)
#>   9. │       └─dplyr:::summarise.data.frame(...)
#>  10. │         └─dplyr:::summarise_cols(.data, dplyr_quosures(...), by, "summarise")
#>  11. │           ├─base::withCallingHandlers(...)
#>  12. │           └─dplyr:::map(quosures, summarise_eval_one, mask = mask)
#>  13. │             └─base::lapply(.x, .f, ...)
#>  14. │               └─dplyr (local) FUN(X[[i]], ...)
#>  15. │                 └─mask$eval_all_summarise(quo)
#>  16. │                   └─dplyr (local) eval()
#>  17. ├─stats::quantile(CFI_M, c(0.95, 0.9))
#>  18. ├─stats:::quantile.default(CFI_M, c(0.95, 0.9))
#>  19. │ └─base::stop("missing values and NaN's not allowed if 'na.rm' is FALSE")
#>  20. └─base::.handleSimpleError(...)
#>  21.   └─dplyr (local) h(simpleError(msg, call))
#>  22.     └─dplyr (local) handler(cnd)
#>  23.       └─rlang::abort(message, class = error_class, parent = parent, call = error_call)
Created on 2024-01-01 with reprex v2.0.2

Session info