cp.chisq.test: Comparative Chi-Squared Test for Difference Across...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/CPChisq.R

Description

Across given contingency tables, the test admits any type of differences in either the joint or marginal distributions underlying the tables.

Usage

1
2
3
4
cp.chisq.test(
  tables, method=c("chisq", "nchisq", "default", "normalized"),
  log.p = FALSE
)

Arguments

tables

a list of at least two nonnegative matrices or data frames representing contingency tables of the same dimensions.

method

a character string to specify the method to compute the chi-squared statistic and its p-value. The default is "chisq". See Details.

Note: "default" and "normalized" are deprecated.

log.p

logical; if TRUE, the p-value is given as log(p). Taking the log improves the accuracy when p-value is close to zero. The default is FALSE.

Details

The comparative chi-squared test determines whether the patterns underlying multiple contingency tables are heterogeneous. Its null test statistic is proved to asymptotically follow the chi-squared distribution \insertCitesong2014hunting,zhang2015chinetDiffXTables. This test is different from the heterogeneity test \insertCitezar2009biostatisticalDiffXTables.

Two methods are provided to compute the chi-squared statistic and its p-value. When method = "chisq" (or "default"), the p-value is computed using the chi-squared distribution; when method = "nchisq" (or "normalized") a normalized statistic is obtained by shifting and scaling the original chi-squared test statistic and a p-value is computed using the standard normal distribution \insertCitegeorge2005statisticsDiffXTables. The normalized test is more conservative on the degrees of freedom.

Either test statistic is minimized to zero if and only if the input tables are linearly scaled versions of each other.

The test is recommended to determine whether multiple contingency tables have the same distributions, regardless of independence of row and column variables in each table.

Value

A list with class "htest" containing the following components:

statistic

chi-squared test statistic if method = "chisq" (equivalent to "default"), or normalized test statistic if method = "nchisq" (equivalent to "normalized").

parameter

degrees of freedom of the chi-squared statistic.

p.value

p-value of the comparative chi-squared test. By default, it is computed by the chi-squared distribution (method = "chisq" or "default"). If method = "nchisq" (or "normalized"), it is the p-value of the normalized chi-squared statistic using the standard normal distribution.

Author(s)

Joe Song

References

\insertAllCited

See Also

The Sharma-Song test sharma.song.test.

The heterogeneity test heterogeneity.test.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  # Two second-order differential tables:
  tables <- list(
    matrix(c(4,0,0,
             0,4,0,
             0,0,4), nrow=3),
    matrix(c(0,4,4,
             4,0,4,
             4,4,0), nrow=3)
  )
  cp.chisq.test(tables)
  
  # Three tables differ in the first-order but not second-order:
  tables <- list(
    matrix(c(2, 4,  6,  8, 
             3, 6,  9, 12, 
             4, 8, 12, 16), nrow=4),
    matrix(c( 2, 1,  3,  7,
              2, 1,  3,  7,
             10, 5, 15, 35), nrow=4),
    matrix(c(40, 16, 72, 16, 
             45, 18, 81, 18,
             25, 10, 45, 10), nrow=4)
  )
  cp.chisq.test(tables)

DiffXTables documentation built on May 16, 2021, 9:07 a.m.