From 19a21d0fcdde9cbc0e8be6d0d90dd28244e64784 Mon Sep 17 00:00:00 2001 From: Johnny Date: Tue, 9 Apr 2024 17:05:53 +0200 Subject: [PATCH] More updating unit tests --- R/regressionlinear.R | 2 +- .../field-residuals-predicted.svg | 476 +++++++++--------- ...ginal-effect-of-contcor1-on-contnormal.svg | 18 +- ...inal-effect-of-contgamma-on-contnormal.svg | 24 +- .../regressionlinear/residuals-dependent.svg | 222 ++++---- .../regressionlinear/residuals-histogram.svg | 16 +- .../regressionlinear/residuals-predicted.svg | 232 ++++----- .../_snaps/regressionlinear/residuals-q-q.svg | 226 ++++----- tests/testthat/test-regressionlinear.R | 27 +- .../test-regressionlinearVerification.R | 3 +- 10 files changed, 623 insertions(+), 623 deletions(-) diff --git a/R/regressionlinear.R b/R/regressionlinear.R index a12048ed..3302594f 100755 --- a/R/regressionlinear.R +++ b/R/regressionlinear.R @@ -764,7 +764,7 @@ RegressionLinearInternal <- function(jaspResults, dataset = NULL, options) { partialPlotContainer$position <- position modelContainer[["partialPlotContainer"]] <- partialPlotContainer - predictors <- .linregGetPredictors(options$modelTerms) + predictors <- .linregGetPredictors(options$modelTerms[[length(options$modelTerms)]][["components"]]) if (any(.linregIsInteraction(predictors))) { .linregCreatePlotPlaceholder(partialPlotContainer, index = "placeholder", title = "") partialPlotContainer$setError(gettext("Partial plots are not supported for models containing interaction terms")) diff --git a/tests/testthat/_snaps/regressionlinear/field-residuals-predicted.svg b/tests/testthat/_snaps/regressionlinear/field-residuals-predicted.svg index 46801d70..2d001c88 100644 --- a/tests/testthat/_snaps/regressionlinear/field-residuals-predicted.svg +++ b/tests/testthat/_snaps/regressionlinear/field-residuals-predicted.svg @@ -27,252 +27,260 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + --200 --100 -0 -100 -200 -300 +-150 +-100 +-50 +0 +50 +100 +150 - - - - + + + + + - - - - - - --2 --1 -0 -1 -2 -3 + + + + + + + +-3 +-2 +-1 +0 +1 +2 +3 - - - - + + + + + + -50 -100 -150 -200 -250 -300 +0 +50 +100 +150 +200 +250 +300 +350 Predicted Values Residuals Standardized Residuals diff --git a/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contcor1-on-contnormal.svg b/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contcor1-on-contnormal.svg index a0ee55cc..ff5eb4ba 100644 --- a/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contcor1-on-contnormal.svg +++ b/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contcor1-on-contnormal.svg @@ -129,19 +129,19 @@ - + --0.4 --0.2 -0.0 -0.2 - - - - +-0.4 +-0.2 +0.0 +0.2 + + + + diff --git a/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contgamma-on-contnormal.svg b/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contgamma-on-contnormal.svg index 8358609c..34545dcb 100644 --- a/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contgamma-on-contnormal.svg +++ b/tests/testthat/_snaps/regressionlinear/marginal-effect-of-contgamma-on-contnormal.svg @@ -129,21 +129,23 @@ - + --0.35 --0.30 --0.25 --0.20 --0.15 - - - - - +-0.40 +-0.35 +-0.30 +-0.25 +-0.20 +-0.15 + + + + + + diff --git a/tests/testthat/_snaps/regressionlinear/residuals-dependent.svg b/tests/testthat/_snaps/regressionlinear/residuals-dependent.svg index 8d59e1dc..1f0d2fd2 100644 --- a/tests/testthat/_snaps/regressionlinear/residuals-dependent.svg +++ b/tests/testthat/_snaps/regressionlinear/residuals-dependent.svg @@ -28,109 +28,109 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -152,18 +152,18 @@ - - + + - - - --2 --1 + + + +-2 +-1 0 -1 -2 -3 +1 +2 +3 diff --git a/tests/testthat/_snaps/regressionlinear/residuals-histogram.svg b/tests/testthat/_snaps/regressionlinear/residuals-histogram.svg index 87aa95f3..d03c4e4b 100644 --- a/tests/testthat/_snaps/regressionlinear/residuals-histogram.svg +++ b/tests/testthat/_snaps/regressionlinear/residuals-histogram.svg @@ -27,14 +27,14 @@ - - - - - - - - + + + + + + + + diff --git a/tests/testthat/_snaps/regressionlinear/residuals-predicted.svg b/tests/testthat/_snaps/regressionlinear/residuals-predicted.svg index bd34f93c..50635215 100644 --- a/tests/testthat/_snaps/regressionlinear/residuals-predicted.svg +++ b/tests/testthat/_snaps/regressionlinear/residuals-predicted.svg @@ -28,109 +28,109 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -152,29 +152,29 @@ - - + + - - - --2 --1 + + + +-2 +-1 0 -1 -2 -3 +1 +2 +3 --0.2 --0.15 --0.1 --0.05 -0 +-0.5 +-0.4 +-0.3 +-0.2 +-0.1 Predicted Values Residuals Standardized Residuals diff --git a/tests/testthat/_snaps/regressionlinear/residuals-q-q.svg b/tests/testthat/_snaps/regressionlinear/residuals-q-q.svg index 39f50b0e..3481363f 100644 --- a/tests/testthat/_snaps/regressionlinear/residuals-q-q.svg +++ b/tests/testthat/_snaps/regressionlinear/residuals-q-q.svg @@ -27,127 +27,127 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + -3 --2 --1 -0 -1 -2 -3 +-2 +-1 +0 +1 +2 +3 - - - - - - + + + + + + diff --git a/tests/testthat/test-regressionlinear.R b/tests/testthat/test-regressionlinear.R index 35840365..1a821a1b 100644 --- a/tests/testthat/test-regressionlinear.R +++ b/tests/testthat/test-regressionlinear.R @@ -517,12 +517,9 @@ test_that("Fields Book - Chapter 1 results match", { options$covariates <- c("adverts", "airplay", "attract") options$modelTerms <- list( - list(components="adverts", name="model0", title = "Model 0"), - list(components="airplay", name="model0", title = "Model 0"), - list(components="attract", name="model0", title = "Model 0") - ) - list(components=NULL, name="model0", title = "Model 0"), - + list(components=list("adverts"), name="model0", title = "Model 0"), + list(components=list("adverts", "airplay", "attract"), name="model1", title = "Model 1") + ) results <- jaspTools::runAnalysis("RegressionLinear", dataset = "Album Sales.csv", options) output4 <- results[["results"]][["modelContainer"]][["collection"]][["modelContainer_summaryTable"]][["data"]] jaspTools::expect_equal_tables(output4, @@ -605,6 +602,7 @@ test_that("Fields Book - Chapter 3 results match", { options$residualCasewiseDiagnosticType <- "outliersOutside" options$residualCasewiseDiagnosticZThreshold <- 2 options$coefficientCi <- TRUE + results <- jaspTools::runAnalysis("RegressionLinear", dataset = "Album Sales.csv", options) figure3 <- results[["state"]][["figures"]][[1]][["obj"]] # Residuals vs. Predicted jaspTools::expect_equal_plots(figure3, "field-residuals-predicted") @@ -706,7 +704,7 @@ test_that("Fields Book - Chapter 4 results match", { options$dependent <- "Happiness" options$covariates <- c("dummy1", "dummy2") options$modelTerms <- list( - list(components=list("dummy1"), name="model0", title = "Model 0"), + list(components=NULL, name="model0", title = "Model 0"), list(components=list("dummy1", "dummy2"), name="model1", title = "Model 1") ) options$coefficientCi <- TRUE @@ -734,11 +732,11 @@ test_that("Fields Book - Chapter 5 results match", { options$dependent <- "Happiness" options$covariates <- c("Dummy1", "Dummy2") options$modelTerms <- list( - list(components=list("dummy1"), name="model0", title = "Model 0"), - list(components=list("dummy1", "dummy2"), name="model1", title = "Model 1") + list(components=NULL, name="model0", title = "Model 0"), + list(components=list("Dummy1", "Dummy2"), name="model1", title = "Model 1") ) options$coefficientCi <- TRUE - results <- jaspTools::runAnalysis("RegressionLinear", dataset = "Puppies Contrast.csv", options) + results <- jaspTools::runAnalysis("RegressionLinear", dataset = Puppies_Contrast, options) output1a <- results[["results"]][["modelContainer"]][["collection"]][["modelContainer_anovaTable"]][["data"]] jaspTools::expect_equal_tables(output1a, list("TRUE", 5.11864406779661, 10.0666666666667, 20.1333333333333, @@ -765,15 +763,6 @@ test_that("VIF is correct when the model contains factors", { options$covariates <- c("contcor1", "contcor2", "contGamma") options$dependent <- "contNormal" options$factors <- c("contBinom", "facFive") - options$modelTerms <- list( - list(components = "contcor1", isNuisance = FALSE), - list(components = "contcor2", isNuisance = FALSE), - list(components = "contGamma", isNuisance = FALSE), - list(components = "contBinom", isNuisance = FALSE), - list(components = "facFive", isNuisance = FALSE), - list(components = c("contBinom", "facFive"), isNuisance = FALSE), - list(components = c("contcor1", "facFive"), isNuisance = FALSE) - ) options$modelTerms <- list( list(components=NULL, name="model0", title = "Model 0"), list(components=list("contcor1", "contcor2", "contGamma", "contBinom", "facFive", diff --git a/tests/testthat/test-regressionlinearVerification.R b/tests/testthat/test-regressionlinearVerification.R index 18bc9a73..7d91c8f5 100644 --- a/tests/testthat/test-regressionlinearVerification.R +++ b/tests/testthat/test-regressionlinearVerification.R @@ -14,7 +14,8 @@ options$dependent <- "Y" options$covariates <- "MeanCenteredX" options$modelTerms <- list( - list(components="MeanCenteredX", isNuisance=FALSE) + list(components=NULL, name="model0", title = "Model 0"), + list(components=list("MeanCenteredX"), name="model1", title = "Model 1") ) options$descriptives <- TRUE options$residualDurbinWatson <- FALSE