diff --git a/RMarkovBlanket.r b/RMarkovBlanket.r index f850e40..e388943 100644 --- a/RMarkovBlanket.r +++ b/RMarkovBlanket.r @@ -1,5 +1,5 @@ #Efrain Gonzalez -#8/28/2017 +#8/25/2017 #Code for Markov Blanket @@ -289,7 +289,7 @@ k = d prevar <- VariableEndName Pathlisting <- vector("list",length = d) Pathlisting[[d]] <- prevar -for(k in d:1){ +for(k in d:2){ if(k == d){ for(ship in 1:length(AllVarList[[d]])){ if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){ @@ -345,20 +345,52 @@ for(k in d:1){ } else if(modship == 1){ #When modship == 1 then we are referring to a Parent - LCofVar <- grep(paste0("^",prevar,"$"),NewDotP2_2[,1]) - CoVar <- NewDotP2_2[LCofVar,1] - lenC <- length(CoVar) - for(o in 1:lenC){ - if(grepl(CoVar[o],AllVarList[[k]][[intship]]) == TRUE){ - - + lengprevar <- length(prevar) + t <- 1 + ##All children of these parents + TCoVar <- vector("character",length = 0) + ##variables that could have led to these parents + leadVar <- vector("character",length = 0) + for(t in 1: lengprevar){ + LCofVar <- grep(paste0("^",prevar[t],"$"),NewDotP2_2[,1]) + CoVar <- NewDotP2_2[LCofVar,2] + TCoVar <- append(TCoVar,CoVar) + } + TCoVar <- TCoVar[!duplicated(TCoVar)] + s <- 1 + ##Searching for the children that are also in the previous degree + for(s in 1:length(TCoVar)){ + if(sum(grepl(TCoVar[s],AllVarList[[(k - 1)]][[intship]])) >= 1){ + leadVar <- append(leadVar,TCoVar[s]) } - } - + leadVar <- leadVar[!duplicated(leadVar)] + prevar <- leadVar } else if(modship == 2){ - #When modship == 0 then we are referring to a Child + #When modship == 2 then we are referring to a Child + lenprevar <- length(prevar) + x <- 1 + ##All parents of these children + TPoVar <- vector("character",length = 0) + ##variables that could have led to these children based on the + drctVar <- vector("character",length = 0) + for(x in 1:lenprevar){ + LPoVar <- grep(paste0("^",prevar[x],"$"),NewDotP2_2[,2]) + PoVar <- NewDotP2_2[LPoVar,1] + TPoVar <- append(TPoVar,PoVar) + } + TPoVar <- TPoVar[!duplicated(TPoVar)] + y <- 1 + ##Searching for the parents that are also in the previous degree + for(y in 1:length(TPoVar)){ + if(sum(grepl(TPoVar[y],AllVarList[[(k - 1)]][[intship]])) >= 1){ + drctVar <- append(drctVar,TPoVar[y]) + } + } + drctVar <- drctVar[!duplicated(drctVar)] + prevar <- drctVar + }