Rfast (version 1.7.3)

Matrix with G-square tests of indepedence: G-square test of indepdence

Description

G-square test of indepdence with and without permutations.

Usage

g2Test_univariate(data, dc)
g2Test_univariate_perm(data, dc, nperm)

Arguments

data
A numerical matrix with the data.
dc
A numerical value equal to the number of variables (or columns of the data matrix) indicating the number of distinct, unique values (or levels) of each variable. Make sure you give the correct numbers here, otherwise the degrees of freedom will be wrong.
nperm
The number of permutations. The permutations test is slower than without permutations and should be used with small sample sizes or when the contigency tables have zeros. When there are few variables, R's "chisq.test" function is faster, but as the number of variables increase the time difference with R's procedure becomes larger and larger.

Value

A list including: A list including:

Details

The function does all the pairwise $G^2$ test of independence and gives the position inside the matrix. The user must build the associations matrix now, similarly to the correlation matrix. See the examples of how to do that. The p-value is not returned, we live this to the user. See the examples of how to obtain it.

References

Tsamardinos, I., & Borboudakis, G. (2010). Permutation testing improves Bayesian network learning. In Joint European Conference on Machine Learning and Knowledge Discovery in Databases (pp. 322-337). Springer Berlin Heidelberg

See Also

g2Test, g2Test_perm, correls, univglms

Examples

Run this code
nvalues <- 3
nvars <- 10
nsamples <- 10000
data <- matrix( sample( 0:(nvalues - 1), nvars * nsamples, replace = TRUE ), nsamples, nvars )
dc <- rep(nvalues, nvars)
system.time( g2Test_univariate(data = data, dc = dc) )
a <- g2Test_univariate(data = data, dc = dc)
pval <- pchisq(a$statistic, a$df, lower.tail = FALSE)

g <- matrix(0, nvars, nvars)
g[ cbind(a$x, a$y) ] <- a$statistic
g <- g + t(g)
diag(g) <- 0
g  ## matrix of G^2 test statistics

pv <- matrix(0, nvars, nvars)
pv[ cbind(a$x, a$y) ] <- pval
pv <- pv + t(pv)
diag(pv) <- 1
pv  ## matrix of the corresponding p-values

Run the code above in your browser using DataLab