Learn R Programming

pcalg (version 1.1-4)

gSquareDis: G square Test for (Conditional) Independence of Discrete Data

Description

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

Usage

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

Arguments

x,y
position (column number) of variable X (and Y respectively) in the adjacency matrix.
S
position of the conditioning variables in the adjacency set.
dm
data matrix (rows: samples, columns: variables) with binary entries
nlev
vector with numbers of levels for each variable
verbose
logical indicating if detailed output is to be provided.
adaptDF
lower the degrees of freedom by one for each zero count. The value for the degrees of freedom cannot go below 1.

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 alternative to this function.

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. disCItest for a wrapper of this function that can be easily included in skeleton, pc or fci.

Examples

Run this code
## Simulate data
x <- sample(1:3,100,TRUE)
y <- sample(1:4,100,TRUE)
z <- sample(1:2,100,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)

Run the code above in your browser using DataLab