From 6b8f81e7b32ee891d8fd7378852288082cb11376 Mon Sep 17 00:00:00 2001 From: Efrain Gonzalez Date: Mon, 28 Aug 2017 18:08:03 -0400 Subject: [PATCH] Fixed issue with similar variable names and added some experimental work --- RMarkovBlanket.r | 110 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/RMarkovBlanket.r b/RMarkovBlanket.r index 48dd79a..f850e40 100644 --- a/RMarkovBlanket.r +++ b/RMarkovBlanket.r @@ -256,3 +256,113 @@ Blanky <- function(MarkovDegree = 20, VariableStartName = "Alzheimer", VariableE ##The Markov Degree is that found below d } + + + +#############Methods for finding paths############# +###Beyond Here Everything is still experimental### +#Find the path to the variable in question +RshipList <- vector("list",length = d) +l = d +for(l in d:1){ + if(l == d){ + RshipList[[l]] <- VariableEndName + for(ship in 1:length(AllVarList[[d]])){ + if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){ + break + } + } + + } else { + modship <- ship %% 3 + intship <- as.integer(ship/3) + if(modship > 0){ + intship <- intship + 1 + } + RshipList[[l]] <- AllVarList[[l]][[intship]] + ship <- intship + } + #l <- l - 1 +} +#Full actual path +k = d +prevar <- VariableEndName +Pathlisting <- vector("list",length = d) +Pathlisting[[d]] <- prevar +for(k in d:1){ + if(k == d){ + for(ship in 1:length(AllVarList[[d]])){ + if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){ + break + } + } + + } + modship <- ship %% 3 + intship <- as.integer(ship/3) + if(modship > 0){ + intship <- intship + 1 + } + if(modship == 0){ + ##When modship == 0 then we are refering to a CoParent + ##Gives how many children the full set of CoParents has + lenCoP <- length(AllVarList[[k]][[(ship - 1)]]) + ##variables that are actually children of the coparent + actvar <- vector("character",length = 0) + ##Parents of actvar + Pactvar <- vector("character",length =0) + ##variables that could have led to the previous set of variables + Wanvar <- vector("character",length = 0) + m <- 1 + for(m in 1:lenCoP){ + LCPoVar <- grep(paste0("^",AllVarList[[k]][[(ship - 1)]][m],"$"),NewDotP2_2[,2]) + CPoVar <- NewDotP2_2[LCPoVar,1] + lenprevar <- length(prevar) + y <- 1 + for(y in 1:lenprevar){ + + if(sum(grepl(prevar[y],CPoVar)) >= 1){ + actvar <- append(actvar,AllVarList[[k]][[(ship - 1)]][m]) + Pactvar <- append(Pactvar,CPoVar) + } + #y <- y + 1 + } + #m <- m + 1 + + } + Pactvar <- Pactvar[!duplicated(Pactvar)] + ##Searching to see if any of the parents are in the previous degree + ##The right children will have both the current variable and a previous degrees variable as parents + o <- 1 + for(o in 1:length(Pactvar)){ + if(sum(grepl(Pactvar[o],AllVarList[[(k - 1)]][[intship]])) >= 1){ + Wanvar <- append(Wanvar,Pactvar[o]) + } + #o <- o + 1 + } + Wanvar <- Wanvar[!duplicated(Wanvar)] + prevar <- Wanvar + + } 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){ + + + } + + } + + + } else if(modship == 2){ + #When modship == 0 then we are referring to a Child + + } + + ship <- intship + + Pathlisting[[(k - 1)]] <- prevar +} -- 2.29.0