GET.contingency: Test of independence in a 2D contingency table

View source: R/appl_indeptest.r

GET.contingencyR Documentation

Test of independence in a 2D contingency table

Description

Permutation-based test of independence in a 2D contingency table, using the matrix of observed counts as the test statistic.

Usage

GET.contingency(X, nsim = 999, ...)

Arguments

X

A matrix with n rows and 2 columns. Each row contains one bivariate observation.

nsim

The number of random permutations used.

...

Additional parameters to be passed to global_envelope_test. In particularly, alpha specifies the nominal significance level of the test, and type the type of the global envelope test.

Details

Permutation-based test of independence in a 2D contingency table, using the matrix of observed counts as the test statistic.

If the observed data are the pairs {(X_1, Y_1), ..., (X_n, Y_n)}, the permutations are obtained by randomly permuting the values in the second marginal, i.e. {(X_1, Y_{pi(1)}), ..., (X_n, Y_{pi(n)})}.

The test itself is performed using the global envelope test in the chosen version. Text output can be printed in the console by typing the object name. The cells in which the observed value exceeds the upper envelope printed in red, and cells in which the observed value is lower than the lower envelope printed in cyan. Standard output of the global envelope test is also returned and can be plotted or analyzed accordingly.

References

Dvořák, J. and Mrkvička, T. (2022). Graphical tests of independence for general distributions. Computational Statistics 37, 671–699.

Examples

# Generate sample data:
data <- matrix(c(sample(4, size=100, replace=TRUE), sample(2, size=100, replace=TRUE)), ncol=2)
data[,2] <- data[,2] + data[,1]

# Observed contingency table (with row names and column names)
table(data[,1], data[,2])

# Permutation-based envelope test
res <- GET.contingency(data, nsim=999)

res
plot(res)

# Extract the p-value
attr(res,"p")

GET documentation built on Nov. 16, 2022, 5:09 p.m.