View source: R/modified.chisq.statistic.R
| modified.chisq.statistic | R Documentation |
Calculates Pearson's chi-squared test statistic for contingency tables, ignoring entries with zero-expected count.
modified.chisq.statistic(x)
x |
a matrix or data frame of floating or integer numbers to specify a contingency table. Entries must be non-negative. |
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.
The numeric value of the modified Pearson's chi-squared test statistic.
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.
luo2021upsilonUpsilon
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.