Commit 6b8f81e7b32ee891d8fd7378852288082cb11376
1 parent
b992d1b704
Exists in
master
Fixed issue with similar variable names and added some experimental work
Showing
1 changed file
with
110 additions
and
0 deletions
 
Show diff stats
RMarkovBlanket.r
| ... | ... | @@ -256,3 +256,113 @@ Blanky <- function(MarkovDegree = 20, VariableStartName = "Alzheimer", VariableE | 
| 256 | 256 | ##The Markov Degree is that found below | 
| 257 | 257 | d | 
| 258 | 258 | } | 
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | +#############Methods for finding paths############# | |
| 263 | +###Beyond Here Everything is still experimental### | |
| 264 | +#Find the path to the variable in question | |
| 265 | +RshipList <- vector("list",length = d) | |
| 266 | +l = d | |
| 267 | +for(l in d:1){ | |
| 268 | + if(l == d){ | |
| 269 | + RshipList[[l]] <- VariableEndName | |
| 270 | + for(ship in 1:length(AllVarList[[d]])){ | |
| 271 | + if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){ | |
| 272 | + break | |
| 273 | + } | |
| 274 | + } | |
| 275 | + | |
| 276 | + } else { | |
| 277 | + modship <- ship %% 3 | |
| 278 | + intship <- as.integer(ship/3) | |
| 279 | + if(modship > 0){ | |
| 280 | + intship <- intship + 1 | |
| 281 | + } | |
| 282 | + RshipList[[l]] <- AllVarList[[l]][[intship]] | |
| 283 | + ship <- intship | |
| 284 | + } | |
| 285 | + #l <- l - 1 | |
| 286 | +} | |
| 287 | +#Full actual path | |
| 288 | +k = d | |
| 289 | +prevar <- VariableEndName | |
| 290 | +Pathlisting <- vector("list",length = d) | |
| 291 | +Pathlisting[[d]] <- prevar | |
| 292 | +for(k in d:1){ | |
| 293 | + if(k == d){ | |
| 294 | + for(ship in 1:length(AllVarList[[d]])){ | |
| 295 | + if(sum(grepl(paste0("^",VariableEndName,"$"),AllVarList[[d]][[ship]])) > 0){ | |
| 296 | + break | |
| 297 | + } | |
| 298 | + } | |
| 299 | + | |
| 300 | + } | |
| 301 | + modship <- ship %% 3 | |
| 302 | + intship <- as.integer(ship/3) | |
| 303 | + if(modship > 0){ | |
| 304 | + intship <- intship + 1 | |
| 305 | + } | |
| 306 | + if(modship == 0){ | |
| 307 | + ##When modship == 0 then we are refering to a CoParent | |
| 308 | + ##Gives how many children the full set of CoParents has | |
| 309 | + lenCoP <- length(AllVarList[[k]][[(ship - 1)]]) | |
| 310 | + ##variables that are actually children of the coparent | |
| 311 | + actvar <- vector("character",length = 0) | |
| 312 | + ##Parents of actvar | |
| 313 | + Pactvar <- vector("character",length =0) | |
| 314 | + ##variables that could have led to the previous set of variables | |
| 315 | + Wanvar <- vector("character",length = 0) | |
| 316 | + m <- 1 | |
| 317 | + for(m in 1:lenCoP){ | |
| 318 | + LCPoVar <- grep(paste0("^",AllVarList[[k]][[(ship - 1)]][m],"$"),NewDotP2_2[,2]) | |
| 319 | + CPoVar <- NewDotP2_2[LCPoVar,1] | |
| 320 | + lenprevar <- length(prevar) | |
| 321 | + y <- 1 | |
| 322 | + for(y in 1:lenprevar){ | |
| 323 | + | |
| 324 | + if(sum(grepl(prevar[y],CPoVar)) >= 1){ | |
| 325 | + actvar <- append(actvar,AllVarList[[k]][[(ship - 1)]][m]) | |
| 326 | + Pactvar <- append(Pactvar,CPoVar) | |
| 327 | + } | |
| 328 | + #y <- y + 1 | |
| 329 | + } | |
| 330 | + #m <- m + 1 | |
| 331 | + | |
| 332 | + } | |
| 333 | + Pactvar <- Pactvar[!duplicated(Pactvar)] | |
| 334 | + ##Searching to see if any of the parents are in the previous degree | |
| 335 | + ##The right children will have both the current variable and a previous degrees variable as parents | |
| 336 | + o <- 1 | |
| 337 | + for(o in 1:length(Pactvar)){ | |
| 338 | + if(sum(grepl(Pactvar[o],AllVarList[[(k - 1)]][[intship]])) >= 1){ | |
| 339 | + Wanvar <- append(Wanvar,Pactvar[o]) | |
| 340 | + } | |
| 341 | + #o <- o + 1 | |
| 342 | + } | |
| 343 | + Wanvar <- Wanvar[!duplicated(Wanvar)] | |
| 344 | + prevar <- Wanvar | |
| 345 | + | |
| 346 | + } else if(modship == 1){ | |
| 347 | + #When modship == 1 then we are referring to a Parent | |
| 348 | + LCofVar <- grep(paste0("^",prevar,"$"),NewDotP2_2[,1]) | |
| 349 | + CoVar <- NewDotP2_2[LCofVar,1] | |
| 350 | + lenC <- length(CoVar) | |
| 351 | + for(o in 1:lenC){ | |
| 352 | + if(grepl(CoVar[o],AllVarList[[k]][[intship]]) == TRUE){ | |
| 353 | + | |
| 354 | + | |
| 355 | + } | |
| 356 | + | |
| 357 | + } | |
| 358 | + | |
| 359 | + | |
| 360 | + } else if(modship == 2){ | |
| 361 | + #When modship == 0 then we are referring to a Child | |
| 362 | + | |
| 363 | + } | |
| 364 | + | |
| 365 | + ship <- intship | |
| 366 | + | |
| 367 | + Pathlisting[[(k - 1)]] <- prevar | |
| 368 | +} |