Rfast (version 1.7.3)

G-square test of conditional indepdence: G-square test of conditional indepdence

Description

G-square test of conditional indepdence with and without permutations.

Usage

g2Test(data, x, y, cs, dc)
g2Test_perm(data, x, y, cs, dc, nperm)

Arguments

data
A numerical matrix with the data.
x
A number between 1 and the number of columns of data. This indicates which variable to take.
y
A number between 1 and the number of columns of data (other than x). This indicates the other variable whose independence with x is to be tested.
cs
A vector with the indices of the variables to condition upon. It must be non zero and between 1 and the number of variables. If you want unconditional independence test see g2Test_univariate and g2Test_univariate_perm. If there is an overlap between x, y and cs you will get 0 as the value of the test statistic.
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 functions calculates the test statistic of the $G^2$ test of conditional independence between x and y conditional on a set of variable(s) cs.

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_univariate, g2Test_univariate_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)

g2Test( data, 1, 2, 3, c(3, 3, 3) )
g2Test_perm( data, 1, 2, 3, c(3, 3, 3), 1000 )

Run the code above in your browser using DataLab