modified.chisq.statistic: Zero-Tolerant Pearson's Chi-squared Statistic

View source: R/modified.chisq.statistic.R

modified.chisq.statisticR Documentation

Zero-Tolerant Pearson's Chi-squared Statistic

Description

Calculates Pearson's chi-squared test statistic for contingency tables, ignoring entries with zero-expected count.

Usage

modified.chisq.statistic(x)

Arguments

x

a matrix or data frame of floating or integer numbers to specify a contingency table. Entries must be non-negative.

Details

This test is useful if p-value must be returned on a contingency table with valid non-negative counts, where the build-in R implementation of chisq.test could return NA as p-value, regardless of a pattern being strong or weak. See Examples.

Unlike chisq.test, this function handles tables with empty rows or columns (where expected values are 0) by calculating the test statistic over non-zero entries only. This prevents the result from becoming NA, while giving meaningful p-values.

Value

The numeric value of the modified Pearson's chi-squared test statistic.

Note

This function only takes contingency table as input. It does not support goodness-of-fit test on vectors. It does not offer an option to apply Yates's continuity correction on 2 \times 2 tables.

References

\insertRef

luo2021upsilonUpsilon

Examples

library("Upsilon")

# Create a table with empty rows or columns
x <- matrix(c(0, 3, 0, 3, 0, 0), nrow = 2, byrow = TRUE)
print(x)

# Standard chisq.test might warn or fail on a table with empty rows or columns
chisq.test(x) 

# Modified statistic handles it gracefully
modified.chisq.statistic(x)

Upsilon documentation built on March 7, 2026, 5:07 p.m.