Skip to content

Commit

Permalink
Fix output for nonconverged models
Browse files Browse the repository at this point in the history
  • Loading branch information
maltelueken committed Oct 10, 2023
1 parent 4a172ff commit 82bec3b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions R/classicProcess.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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") {
Expand All @@ -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)
Expand Down

0 comments on commit 82bec3b

Please sign in to comment.