disCItest | R Documentation |
G^2
test for (conditional) independence of discrete
(each with a finite number of “levels”)
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
.
gSquareDis(x, y, S, dm, nlev, adaptDF = FALSE, n.min = 10*df, verbose = FALSE)
disCItest (x, y, S, suffStat)
x , y |
(integer) position of variable |
S |
(integer) positions of zero or more conditioning variables in the adjacency matrix. |
dm |
data matrix (rows: samples, columns: variables) with integer entries; the k levels for a given column must be coded by the integers 0,1,...,k-1. (see example) |
nlev |
optional vector with numbers of levels for each variable
in |
adaptDF |
logical specifying if the degrees of freedom should be lowered by one for each zero count. The value for the degrees of freedom cannot go below 1. |
n.min |
the smallest |
verbose |
logical or integer indicating that increased diagnostic output is to be provided. |
suffStat |
a |
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()
.
The p-value of the test.
Nicoletta Andri and Markus Kalisch (kalisch@stat.math.ethz.ch).
R.E. Neapolitan (2004). Learning Bayesian Networks. Prentice Hall Series in Artificial Intelligence. Chapter 10.3.1
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.
## Simulate data
n <- 100
set.seed(123)
x <- sample(0:2, n, TRUE) ## three levels
y <- sample(0:3, n, TRUE) ## four levels
z <- sample(0:1, n, TRUE) ## two levels
dat <- cbind(x,y,z)
## Analyze data
gSquareDis(1,3, S=2, dat, nlev = c(3,4,2)) # but nlev is optional:
gSquareDis(1,3, S=2, dat, verbose=TRUE, adaptDF=TRUE)
## with too little data, gives a warning (and p-value 1):
gSquareDis(1,3, S=2, dat[1:60,], nlev = c(3,4,2))
suffStat <- list(dm = dat, nlev = c(3,4,2), adaptDF = FALSE)
disCItest(1,3,2,suffStat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.