Commit 1c91b280d22441978d31c070257bd8f7131a38ba

Authored by Zhenghua Gong
1 parent 32058197dd
Exists in master

This file is the code to test conditional independence

Showing 1 changed file with 27 additions and 0 deletions   Show diff stats
CondIndependentTest.R
... ... @@ -0,0 +1,27 @@
  1 +CondIndTwoVar =
  2 + function (filename = "/home/zgong001/Documents/SprinklerDataset/sprinkler1001.txt", alphalevel = 0.05, methodu="x2", exfilename = "/home/zgong001/Documents/SprinklerDataset/pvalueSorted(sprinkler).xlsx"){
  3 + library(bnlearn)
  4 + result = data.frame()
  5 + sprinkler <- read.table(filename, header = TRUE)
  6 + columname = colnames(sprinkler)
  7 + m=length(columname)
  8 + x=seq(0,m-1,by=1)
  9 + colnames(sprinkler)=x
  10 + columname = colnames(sprinkler)
  11 + TwoVComb = combn(columname,2)
  12 + for(jt in 1:ncol(TwoVComb)){
  13 + twoV = c(TwoVComb[1,jt], TwoVComb[2,jt])
  14 + columnameT = columname[! columname %in% twoV]
  15 + colComb = combn(columnameT,2)
  16 + for (j in 1:ncol(colComb)){
  17 + citest = ci.test(colComb[1,j], colComb[2,j], twoV, test = methodu, data = sprinkler)
  18 + lable = paste(paste(colComb[1,j], colComb[2,j],sep=", "), "|", paste(twoV[1], twoV[2], sep=", "), sep=" ")
  19 + pvalue = citest$p.value
  20 + CIlist= data.frame("Index" = lable, "pvalue" = pvalue)
  21 + result = rbind(result, CIlist)
  22 + }
  23 + }
  24 + result2 = result[order(-result[,2]), ]
  25 + write.xlsx(result2, exfilename, sheetName = "Sheet1", col.names = TRUE, row.names = TRUE, append = FALSE)
  26 + return(result2)
  27 + }
0 28 \ No newline at end of file