Learn R Programming

MXM (version 0.9.4)

Conditional independence test for binary, categorical or ordinal data: Conditional independence test for binary, categorical or ordinal class variables

Description

The main task of this test is to provide a p-value PVALUE for the null hypothesis: feature 'X' is independent from 'TARGET' given a conditioning set CS. The pvalue is calculated by comparing a logistic model based on the conditioning set CS against a model whose regressor are both X and CS. The comparison is performed through a chi-square test with the aproprirate degrees of freedom on the difference between the deviances of the two models.

Usage

testIndLogistic(target,dataset,xIndex,csIndex,dataInfo = NULL,univariateModels = NULL, hash = FALSE, stat_hash = NULL, pvalue_hash = NULL, target_type = 0, robust = FALSE)

Arguments

target
A numeric vector containing the values of the target variable.
dataset
A numeric matrix or data frame, in case of categorical predictors (factors), containing the variables for performing the test. Rows as samples and columns as features.
xIndex
The index of the variable whose association with the target we want to test.
csIndex
The indices of the variables to condition on.
dataInfo
A list object with information on the structure of the data. Default value is NULL.
univariateModels
Fast alternative to the hash object for univariate test. List with vectors "pvalues" (p-values), "stats" (statistics) and "flags" (flag = TRUE if the test was succesful) representing the univariate association of each variable with the target. Default value is NULL.
hash
A boolean variable which indicates whether (TRUE) or not (FALSE) to use the hash-based implementation of the statistics of SES. Default value is FALSE. If TRUE you have to specify the stat_hash argument and the pvalue_hash argument.
stat_hash
A hash object (hash package required) which contains the cached generated statistics of a SES run in the current dataset, using the current test.
pvalue_hash
A hash object (hash package required) which contains the cached generated p-values of a SES run in the current dataset, using the current test.
target_type
A numeric vector that represents the type of the target. Default value is 0. See details for more.
  • target_type = 1 (binary target)
  • target_type = 2 (nominal target)
  • target_type = 3 (ordinal target)

robust
A boolean variable which indicates whether (TRUE) or not (FALSE) to use a robustified version of the logistic regressions available here. Currently it is not available.

Value

A list including: A list including:

Details

If argument target_type=0 then testIndLogistic requires the dataInfo argument to indicate the type of the current target:
  • dataInfo$target_type = "binary" (binary target)
  • dataInfo$target_type = "nominal" (nominal target)
  • dataInfo$target_type = "ordinal" (ordinal target)

If hash = TRUE, testIndLogistic requires the arguments 'stat_hash' and 'pvalue_hash' for the hash-based implementation of the statistic test. These hash Objects are produced or updated by each run of SES (if hash == TRUE) and they can be reused in order to speed up next runs of the current statistic test. If "SESoutput" is the output of a SES run, then these objects can be retrieved by SESoutput@hashObject$stat_hash and the SESoutput@hashObject$pvalue_hash.

Important: Use these arguments only with the same dataset that was used at initialization.

For all the available conditional independence tests that are currently included on the package, please see "?CondIndTests".

References

Hampel F. R., Ronchetti E. M., Rousseeuw P. J., and Stahel W. A. (1986). Robust statistics: the approach based on influence functions. John Wiley & Sons.

Vincenzo Lagani, George Kortas and Ioannis Tsamardinos (2013), Biomarker signature identification in "omics" with multiclass outcome. Computational and Structural Biotechnology Journal, 6(7):1-7.

McCullagh, Peter, and John A. Nelder. Generalized linear models. CRC press, USA, 2nd edition, 1989.

See Also

SES, testIndSpeedglm, gSquare, CondIndTests

Examples

Run this code
#require(gRbase) #for faster computations in the internal functions
require(nnet)
require(ordinal)

#simulate a dataset with categorical data 
dataset_m <- matrix( sample(c(0, 1, 2), 50 * 100, replace = TRUE), ncol = 50)
#initialize categorical target
target_m <- dataset_m[, 50]
#remove target from the dataset
dataset_m <- dataset_m[, -50]

  #run the conditional independence test for the nominal class variable
  results_m <- testIndLogistic(target_m, dataset_m, xIndex = 44, csIndex = c(10, 20), 
  target_type = 2)
  results_m

  #run the SES algorithm using the testIndLogistic conditional independence test 
  #for the nominal class variable
  sesObject <- SES(as.factor(target_m), dataset_m, max_k = 3, threshold = 0.05, 
  test = "testIndLogistic");
  #print summary of the SES output
  summary(sesObject);
  #plot the SES output
  plot(sesObject, mode = "all");


########################################################################

  #run the conditional independence test for the ordinal class variable
  results_o <- testIndLogistic(target_m, dataset_m, xIndex = 44, csIndex = c(10, 20), 
  target_type = 3)
  results_o
  
  #run the SES algorithm using the testIndLogistic conditional independence test 
  #for the ordinal class variable
  sesObject <- SES(factor(target_m, ordered=TRUE), dataset_m, max_k = 3 , 
  threshold = 0.05, 
                   test = "testIndLogistic");
  #print summary of the SES output
  summary(sesObject);
  #plot the SES output
  plot(sesObject, mode = "all");


########################################################################

#simulate a dataset with binary data
dataset_b <- matrix(sample(c(0,1),50 * 60, replace = TRUE), ncol = 50)
#initialize binary target
target_b <- dataset_b[, 50]
#remove target from the dataset
dataset_b <- dataset_b[, -50]

  #run the conditional independence test for the binary class variable
  results_b <- testIndLogistic(target_b, dataset_b, xIndex = 44, csIndex = c(10, 20), 
  target_type = 1)
  results_b
  
  #run the SES algorithm using the testIndLogistic conditional independence test
  #for the binary class variable
  sesObject <- SES(target_b, dataset_b, max_k = 3, threshold = 0.05, 
  test = "testIndLogistic");
  #print summary of the SES output
  summary(sesObject);
  #plot the SES output
  plot(sesObject, mode = "all");

Run the code above in your browser using DataLab