Conditional independence tests

bnlearn implements several conditional independence tests for the constraint-based learning algorithms (see the overview of the package for a complete list). They can be used directly ci.test function, which takes two variables x and y and an optional set of conditioning variables z as arguments.

Parametric tests

Here are some examples, listed according to the form of ci.test's arguments (see the manual page of the lizards data set for details on the data).

  1. x, y, z are character strings, the names of columns of the matrix or data frame specified by data.
    > data(lizards)
    > ci.test("Height", "Diameter", "Species", data=lizards, test = "mi")
    
            Mutual Information (discrete)
    
    data:  Height ~ Diameter | Species
    mi = 2.0256, df = 2, p-value = 0.3632
    alternative hypothesis: true value is greater than 0
    
    
  2. if the only argument is a matrix or a data frame, the first column is taken to be x, the second on y and the following ones z.
    > ci.test(lizards, test = "mi")
    
            Mutual Information (discrete)
    
    data:  Species ~ Diameter | Height
    mi = 14.0241, df = 2, p-value = 0.000901
    alternative hypothesis: true value is greater than 0
    
    
  3. x, y and z are either distinct R objects or columns extracted from a data frame or a matrix.
    > ci.test(lizards$Diameter, lizards$Height, lizards$Species, test = "mi")
    
            Mutual Information (discrete)
    
    data:  lizards$Diameter ~ lizards$Height | lizards$Species
    mi = 2.0256, df = 2, p-value = 0.3632
    alternative hypothesis: true value is greater than 0
    
    
    > attach(lizards)
    > ci.test(Height, Diameter, Species, test = "mi")
    
            Mutual Information (discrete)
    
    data:  Height ~ Diameter | Species
    mi = 2.0256, df = 2, p-value = 0.3632
    alternative hypothesis: true value is greater than 0
    
    

Different tests can be specified with the test parameter (see bnlearn's manual page for an overiew).

Monte Carlo permutation tests

Nonparametric tests are performed in the same way as their parametric counterparts, except that the number of permutations used in the estimation of the observed significance may be specified via the B parameter (the default value is 5000). For example:

> attach(lizards)
> ci.test(Diameter, Height, Species, test = "mc-x2")

	Pearson's X^2 (Monte Carlo)

data:  Diameter ~ Height | Species 
mc-x2 = 2.0174, Monte Carlo samples = 5000, p-value = 0.3668
alternative hypothesis: true value is greater than 0 

> ci.test(Diameter, Height, Species, test = "mc-x2", B = 10^4)

	Pearson's X^2 (Monte Carlo)

data:  Diameter ~ Height | Species 
mc-x2 = 2.0174, Monte Carlo samples = 10000, p-value = 0.3603
alternative hypothesis: true value is greater than 0