View source: R/appl_indeptest.r
GET.contingency | R Documentation |
Permutation-based test of independence in a 2D contingency table, using the matrix of observed counts as the test statistic.
GET.contingency(X, nsim = 999, ...)
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 |
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.
Dvořák, J. and Mrkvička, T. (2022). Graphical tests of independence for general distributions. Computational Statistics 37, 671–699.
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.