Skip to content

Commit

Permalink
disable continuity correction for non 2x2 tables
Browse files Browse the repository at this point in the history
fixes: jasp-stats/jasp-issues#2829

Co-authored-by: Don van den Bergh <[email protected]>
  • Loading branch information
FBartos and vandenman authored Nov 8, 2024
1 parent 00977e1 commit a013d15
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions R/contingencytables.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ ContingencyTablesInternal <- function(jaspResults, dataset, options, ...) {
groupList <- .crossTabComputeGroups(dataset, options, analysisContainer, analysis, ready) # Compute/get Group List
res <- try(.crossTabTestsRows(analysisContainer, groupList$rows, groupList, options, ready, counts.fp))

if (ready && !.crossTabIs2x2(table(dataset[[analysis[["columns"]]]], dataset[[analysis[["rows"]]]])))
crossTabChisq$addFootnote(gettext("Continuity correction is available only for 2x2 tables."))

.crossTabSetErrorOrFill(res, crossTabChisq)
}
}
Expand Down Expand Up @@ -717,18 +720,22 @@ ContingencyTablesInternal <- function(jaspResults, dataset, options, ...) {
return(unlist(rowNames))
}

.crossTabIs2x2 <- function(counts.matrix) {
return(all(dim(counts.matrix) == 2L))
}

.crossTabMainNote <- function(options) {

if (options$countsObserved) outputType <- gettext("observed counts")
else if (options$countsExpected) outputType <- gettext("expected counts")
else if (options$percentagesRow) outputType <- gettext("row percentages")
else if (options$percentagesColumn) outputType <- gettext("column percentages")
else if (options$percentagesTotal) outputType <- gettext("total percentages")
else if (options$residualsUnstandardized) outputType <- gettext("unstandardized residuals")
else if (options$residualsPearson) outputType <- gettext("Pearson residuals")
else if (options$residualsStandardized) outputType <- gettext("standardized residuals")
if (options$countsObserved) return(gettext("Each cell displays the observed counts"))
else if (options$countsExpected) return(gettext("Each cell displays the expected counts"))
else if (options$percentagesRow) return(gettext("Each cell displays the row percentages"))
else if (options$percentagesColumn) return(gettext("Each cell displays column percentages"))
else if (options$percentagesTotal) return(gettext("Each cell displays total percentages"))
else if (options$residualsUnstandardized) return(gettext("Each cell displays unstandardized residuals"))
else if (options$residualsPearson) return(gettext("Each cell displays Pearson residuals"))
else if (options$residualsStandardized) return(gettext("Each cell displays standardized residuals"))

return(gettextf("Each cell displays the %1$s.", outputType))
stop("unreachable point in .crossTabMainNote was reached!")
}

# Group matrix
Expand Down Expand Up @@ -1080,7 +1087,7 @@ ContingencyTablesInternal <- function(jaspResults, dataset, options, ...) {

row[["type[chiSquared-cc]"]] <- gettextf("%s continuity correction", "\u03A7\u00B2")

if (ready) {
if (ready && .crossTabIs2x2(counts.matrix)) {

chi.result <- try({
chi.result <- stats::chisq.test(counts.matrix)
Expand Down

0 comments on commit a013d15

Please sign in to comment.