View source: R/modified.chisq.test.R
| modified.chisq.test | R Documentation |
Performs Pearson's chi-squared test \insertCitepearson1900Upsilon on contingency tables, slightly modified to handle rows or columns of all zeros.
modified.chisq.test(x, log.p = FALSE)
x |
a matrix or data frame of floating or integer numbers to specify a contingency table. Entries must be non-negative. |
log.p |
a logical. If |
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.
A list with class "htest" containing:
statistic |
the chi-squared test statistic (calculated ignoring entries of 0-expected count). |
parameter |
the degrees of freedom. |
p.value |
the p-value by the test. |
estimate |
Cramér's V statistic. |
observed |
the observed counts. |
expected |
the expected counts under the null hypothesis. |
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.
pearson1900Upsilon
library("Upsilon")
# A table with a dominant function and an empty column
x <- matrix(
c(0, 3, 0,
3, 0, 0),
nrow = 2, byrow = TRUE)
print(x)
# Standard chisq.test fails or returns NA warning
chisq.test(x)
# Modified chi-squared test is significant:
modified.chisq.test(x)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.