Skip to content

Commit

Permalink
Fix unit tests for blocked models logistic reg
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyDoorn committed Apr 24, 2024
1 parent 8a91325 commit e3ae7a7
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 97 deletions.
6 changes: 4 additions & 2 deletions R/commonglm.R
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@
if (isFALSE(options[["residualsSavedToData"]]))
return()

if (is.null(container[["residualsSavedToDataColumn"]]) && options[["residualsSavedToDataColumn"]] != "") {
if (is.null(container[["residualsSavedToDataColumn"]]) &&
isFALSE(is.null(options[["residualsSavedToDataColumn"]])) &&
options[["residualsSavedToDataColumn"]] != "") {

residuals <- model[["residuals"]] # extract residuals

Expand Down Expand Up @@ -856,7 +858,7 @@
colnames(influenceResData)[1:length(colInd)] <- colNames[1:length(colInd)]

influenceResData[["caseN"]] <- seq.int(nrow(influenceResData))
influenceResData[["stdResidual"]] <- rstandard(model)
influenceResData[["stdResidual"]] <- rstandard(model, type = "deviance")
influenceResData[["dependent"]] <- model.frame(model)[[options$dependent]]
influenceResData[["predicted"]] <- model$fitted.values
influenceResData[["residual"]] <- model$residual
Expand Down
3 changes: 2 additions & 1 deletion R/regressionlogistic.R
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ RegressionLogisticInternal <- function(jaspResults, dataset = NULL, options, ...
mObj <- glmObj[[midx]]
if (midx > 1) {
if (options$method == "forward" ||
options$method == "stepwise") {
options$method == "stepwise" ||
options$method == "enter") {
fadden <- .mcFadden(mObj, glmObj[[1]])
nagel <- .nagelkerke(mObj, glmObj[[1]])
coxSn <- .coxSnell(mObj, glmObj[[1]])
Expand Down
2 changes: 1 addition & 1 deletion inst/qml/RegressionLogistic.qml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Form
CheckBox { name: "hMeasure"; label: qsTr("H-measure") }
}

Common.OutlierComponent { id: outlierComponentt}
Common.OutlierComponent { id: outlierComponent}


}
Expand Down
6 changes: 5 additions & 1 deletion inst/qml/common/OutlierComponent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ Group
name: "residualStatistic"
label: qsTr("Statistics")
visible: analysis === Type.Analysis.LinearRegression
value: false
}

CheckBox
{
name: "residualCasewiseDiagnostic"; label: qsTr("Casewise diagnostics")
name: "residualCasewiseDiagnostic"
label: qsTr("Casewise diagnostics")
value: false
columns: 2
RadioButtonGroup
{
Expand Down Expand Up @@ -71,6 +74,7 @@ Group
id: residualsSavedToData
name: "residualsSavedToData"
text: qsTr("Append residuals to data")
value: false

ComputedColumnField
{
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/helper-regression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
initClassicalRegressionOptions <- function(analysis = c("RegressionLinear", "RegressionLogistic")) {
analysis <- match.arg(analysis)
options <- c(
jaspTools::analysisOptions(analysis),
classicalRegressionCommonOptions()
)

return(options)
}

classicalRegressionCommonOptions <- function() {
path <- testthat::test_path("..", "..", "inst", "qml", "common")
files <- list.files(path, full.names = TRUE)
options <- lapply(files, jaspTools:::readQML) |>
lapply(function(x) {x$plotWidth <- NULL; x$plotHeight <- NULL; return(x)}) |>
(function(x) { do.call(c, x)})()

return(options)
}

187 changes: 96 additions & 91 deletions tests/testthat/test-regressionlogistic.R

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/testthat/test-regressionlogisticVerification.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ context("Logistic Regression -- Verification project")

## Testing Titanice

options <- jaspTools::analysisOptions("RegressionLogistic")
options <- initClassicalRegressionOptions("RegressionLogistic")
options$dependent <- "Survived"
options$factors <- c("PClass", "Sex")
options$covariates <- "Age"
Expand Down

0 comments on commit e3ae7a7

Please sign in to comment.