From 2efe5909448ed1222fb1e9b85f50d85d488d8270 Mon Sep 17 00:00:00 2001 From: maltelueken Date: Wed, 11 Oct 2023 09:17:46 +0200 Subject: [PATCH] Fix output for nonconverged models --- R/classicProcess.R | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/R/classicProcess.R b/R/classicProcess.R index bd28113..5e2cc65 100644 --- a/R/classicProcess.R +++ b/R/classicProcess.R @@ -915,7 +915,7 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) { # Output functions ---- .procFilterFittedModels <- function(procResults) { isFitted <- sapply(procResults, function(mod) { - if (!is.null(mod) && !is.character(mod)) + if (!is.null(mod) && !is.character(mod) && mod@Fit@converged) return(mod@Options[["do.fit"]]) return(FALSE) }) @@ -978,13 +978,20 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) { .procModelSummaryTable <- function(jaspResults, options, modelsContainer) { if (!is.null(jaspResults[["modelSummaryTable"]])) return() - procResults <- lapply(options[["processModels"]], function(mod) modelsContainer[[mod[["name"]]]][["fittedModel"]]$object) - procResults <- .procFilterFittedModels(procResults) - summaryTable <- createJaspTable(title = gettext("Model summary")) summaryTable$dependOn(c(.procGetDependencies(), "processModels", "aicWeights", "bicWeights", "naAction")) summaryTable$position <- 1 + procResults <- lapply(options[["processModels"]], function(mod) modelsContainer[[mod[["name"]]]][["fittedModel"]]$object) + + converged <- sapply(procResults, function(mod) mod@Fit@converged) + + if (!all(converged)) { + summaryTable$addFootnote(message = gettext("At least one model did not converge.")) + } + + procResults <- .procFilterFittedModels(procResults) + if (options[["naAction"]] == "fiml" && !options[["estimator"]] %in% c("default", "ml")) { summaryTable$setError("Full Information Maximum Likelihood estimation only available with 'ML' or 'Auto' estimators. Please choose a different estimator or option for missing value handling.") } @@ -1012,7 +1019,7 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) { summaryTable$setError(errmsg) } - if (length(procResults) == 0) return() + modelNames <- sapply(options[["processModels"]], function(mod) mod[["name"]]) modelNumbers <- lapply(options[["processModels"]], function(mod) { if (mod[["inputType"]] == "inputModelNumber") { @@ -1025,14 +1032,15 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) { return(.procRecognizeModelNumber(modelsContainer[[mod[["name"]]]][["graph"]]$object)) }) - modelNames <- sapply(options[["processModels"]], function(mod) mod[["name"]]) + summaryTable[["Model"]] <- modelNames + summaryTable[["modelNumber"]] <- modelNumbers + + if (length(procResults) == 0) return() aic <- sapply(procResults, AIC) bic <- sapply(procResults, BIC) df <- sapply(procResults, lavaan::fitMeasures, fit.measures = "df") - summaryTable[["Model"]] <- modelNames - summaryTable[["modelNumber"]] <- modelNumbers summaryTable[["AIC"]] <- aic summaryTable[["BIC"]] <- bic summaryTable[["logLik"]] <- sapply(procResults, lavaan::logLik)