Learn R Programming

pcalg (version 1.0-2)

gSquareDis: Test for (conditional) independence for discrete data

Description

G^2 statistic to test for (conditional) independence of X and Y given set S.

Usage

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

Arguments

x
Position of variable X in the adjacency matrix
y
Position of variable Y 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
If TRUE, detailed output is 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 (cann 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))

Run the code above in your browser using DataLab