Learn R Programming

pcalg (version 1.0-0)

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 node X in adjacency matrix
y
Position of node Y in adjacency matrix
S
Position of set of nodes in adjacency matrix on which is conditioned
dm
Data matrix (rows: samples, columns: variables) with binary entries
nlev
Vector with numbers of levels for each variable
verbose
Additional output if TRUE
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 is returned.

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.

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