From 82bec3ba5a0bcaf3f0449c30d37377f4d4c40b23 Mon Sep 17 00:00:00 2001 From: maltelueken Date: Tue, 10 Oct 2023 16:28:01 +0200 Subject: [PATCH] Fix output for nonconverged models --- R/classicProcess.R | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/R/classicProcess.R b/R/classicProcess.R index bd28113..018be80 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) }) @@ -979,6 +979,13 @@ procModelGraphSingleModel <- function(modelOptions, globalDependent, options) { if (!is.null(jaspResults[["modelSummaryTable"]])) return() 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) summaryTable <- createJaspTable(title = gettext("Model summary")) @@ -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)