Learn R Programming

pcalg (version 2.0-3)

disCItest: G square Test for (conditional) Independence for Discrete Data

Description

$G^2$ test for (conditional) independence of discrete variables $X$ and $Y$ given the (possibly empty) set of discrete variables $S$.

disCItest() is a wrapper of gSquareDis(), to be easily used in skeleton, pc and fci.

Usage

gSquareDis(x, y, S, dm, nlev, adaptDF = FALSE, verbose = FALSE)
disCItest (x, y, S, suffStat)

Arguments

x
Position of variable X in the adjacency matrix
y
Position of variable Y in the adjacency matrix
S
Position of conditioning variables in the adjacency matrix
dm
Data matrix (rows: samples, columns: variables) with binary entries
nlev
Vector with numbers of levels for each variable
adaptDF
Lower the degrees of freedom by one for each zero count. The value for the degrees of freedom cannot go below 1.
verbose
Logical indicating if detailed output is to be provided.
suffStat
A list with three elements: "dm", "nlev", "adaptDF"; each corresponding to the above arguments of gSquareDis().

Value

  • The p-value of the test.

Details

The $G^2$ statistic is used to test for (conditional) independence of X and Y given a set S (can be NULL). If only binary variables are involved, gSquareBin is a specialized (a bit more efficient) alternative to gSquareDis().

References

R.E. Neapolitan (2004). Learning Bayesian Networks. Prentice Hall Series in Artificial Intelligence. Chapter 10.3.1

See Also

gSquareBin for a (conditional) independence test for binary variables.

dsepTest, gaussCItest and binCItest for similar functions for a d-separation oracle, a conditional independence test for gaussian variables and a conditional independence test for binary variables, respectively.

Examples

Run this code
## Simulate data
n <- 100
set.seed(123)
x <- sample(0:2, n, TRUE)
y <- sample(0:3, n, TRUE)
z <- sample(0:1, n, TRUE)
dat <- cbind(x,y,z)

## Analyze data
gSquareDis(1,3,2,dat,nlev = c(3,4,2))
gSquareDis(1,3,2,dat,nlev = c(3,4,2), verbose=TRUE, adaptDF=TRUE)

suffStat <- list(dm = dat, nlev = c(3,4,2), adaptDF = FALSE)
disCItest(1,3,2,suffStat)

Run the code above in your browser using DataLab