R/voteAllRules.R

Defines functions voteAllRules

Documented in voteAllRules

voteAllRules <-
function(ruleMetric,X,type="r",method="median"){
  xVoteList = vector("list",nrow(X))
  predY <- rep("",nrow(X))
  for(i in 1:nrow(ruleMetric)){
    ixMatch <- eval(parse(text=paste("which(",ruleMetric[i,"condition"], ")"))  ) 
    if(length(ixMatch)==0) next
    for(ii in ixMatch){
      xVoteList[[ii]] = c(xVoteList[[ii]], ruleMetric[i,"pred"])
    }
  }
  for(i in 1:length(xVoteList)){
    thisV <- xVoteList[[i]]
    if(length(thisV)==0) next
    if(type == "c") predY[i] <- names(table(thisV)[which.max(table(thisV))])
    if(type == "r"){
      thisV = as.numeric(thisV)
      if(method == "median"){
        predY[i] <- median(thisV)
      }else{
        predY[i] <- mean(thisV)
      }
    }
 
  }
  if(type=="r") predY <- as.numeric(predY)
  return(predY)
}

Try the inTrees package in your browser

Any scripts or data that you put into this service are public.

inTrees documentation built on June 1, 2022, 1:06 a.m.