Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error check to correlation #324

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions R/correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
CorrelationInternal <- function(jaspResults, dataset, options){
dataset <- .corrReadData(dataset, options)
ready <- length(options$variables) >= 2

if (ready)
.hasErrors(dataset, type = c("infinity", "variance", "observations"),
observations.amount = "< 3",
observations.target = options$variables,
exitAnalysisIfErrors = TRUE)


corrResults <- .corrMainResults(jaspResults, dataset, options, ready)

Expand Down
29 changes: 3 additions & 26 deletions tests/testthat/test-correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,9 @@ test_that("Analysis handles errors", {
options$variables <- list("contNormal", "debMiss99", "debSame")
set.seed(1)
results <- jaspTools::runAnalysis("Correlation", "debug.csv", options)
table <- results[["results"]][["mainTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
"NaN", "NaN", "-", "contNormal", "debMiss99", 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "NaN", "NaN",
"-", "contNormal", "debSame", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "NaN", "NaN", "-", "debMiss99",
"debSame"))
expect_identical(results[["results"]][["errorMessage"]],
"The following problem(s) occurred while running the analysis:<ul><li>The variance in debSame is equal to 0</li><li>Number of observations is < 3 in debMiss99</li></ul>",
label="Inf covariate check")
})


Expand Down Expand Up @@ -280,21 +275,3 @@ test_that("Bootstrapping results match", {
0.121736428310888, "contcor1", "debMiss30"))
})

test_that("Bootstrapping fails gracefully", {
options <- jaspTools::analysisOptions("Correlation")
options$variables <- c("contNormal", "debMiss99")
options$partialOutVariables <- c("facFive")
options$ciBootstrap <- TRUE
options$ciBootstrapSamples <- 100
options$ci <- TRUE

set.seed(1)
results <- jaspTools::runAnalysis("Correlation", "debug.csv", options)

table <- results[["results"]][["mainTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
"<unicode>", "<unicode>", "<unicode>", "<unicode>", "NaN", "NaN",
"NaN", "NaN", "contNormal", "", "", "", "", "<unicode>", "<unicode>",
"<unicode>", "<unicode>", "debMiss99"))
})
Loading