#require(gRbase) #for faster computations in the internal functions
require(VGAM)
require(MASS)
require(stats)
#simulate a dataset with categorical data
dataset_m <- matrix(nrow = 20 , ncol = 51)
dataset_m <- apply(dataset_m, 2, function(i) sample(c(0,1,2),50, replace=TRUE))
#initialize categorical target
target_m <- dataset_m[,51]
#remove target from the dataset
dataset_m <- dataset_m[,-51]
if(require("VGAM", quietly = TRUE))
{
#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");
}
########################################################################
if(require("MASS", quietly = TRUE))
{
#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(nrow = 20 , ncol = 51)
dataset_b <- apply(dataset_b, 2, function(i) sample(c(0,1),50, replace=TRUE))
#initialize binary target
target_b <- dataset_b[,51]
#remove target from the dataset
dataset_b <- dataset_b[,-51]
if(require("stats", quietly = TRUE))
{
#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(factor(target_b), 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 code above in your browser using DataLab