2015-05-31 21:09:04 +02:00
|
|
|
# FORESTS -----------------------------------------------------------------
|
|
|
|
|
2015-06-10 16:48:18 +02:00
|
|
|
#' Difft by Random Forest
|
2015-06-01 23:22:49 +02:00
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' An abstract reference class to compute twin via random forests
|
|
|
|
#'
|
|
|
|
#' \code{VT.forest} extends \code{VT.difft}
|
|
|
|
#'
|
2015-06-12 00:34:25 +02:00
|
|
|
#' @field ... see fields of \code{\link{VT.difft}}
|
2015-06-10 16:48:18 +02:00
|
|
|
#'
|
2015-06-01 23:22:49 +02:00
|
|
|
#' @include difft.R predict.R
|
2015-06-10 16:48:18 +02:00
|
|
|
#'
|
|
|
|
#' @name VT.forest
|
2015-06-01 23:22:49 +02:00
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
|
|
|
#'
|
|
|
|
#' @import methods
|
2015-05-31 21:09:04 +02:00
|
|
|
VT.forest <- setRefClass(
|
|
|
|
Class = "VT.forest",
|
|
|
|
|
|
|
|
contains = "VT.difft",
|
|
|
|
|
|
|
|
methods = list(
|
|
|
|
run = function(){
|
2015-06-10 16:48:18 +02:00
|
|
|
"Compute twin1 and twin2 estimation. Switch treatment if necessary."
|
2015-05-31 21:09:04 +02:00
|
|
|
.self$computeTwin1()
|
|
|
|
|
|
|
|
if(inherits(.self, "VT.forest.one")) .self$vt.object$switchTreatment() #if one forest
|
|
|
|
|
|
|
|
.self$computeTwin2()
|
|
|
|
|
|
|
|
if(inherits(.self, "VT.forest.one")) .self$vt.object$switchTreatment() #if one forest
|
|
|
|
|
|
|
|
.self$computeDifft()
|
|
|
|
|
|
|
|
.self$vt.object$computeDelta() # To see later
|
|
|
|
|
|
|
|
return(invisible(.self))
|
|
|
|
},
|
|
|
|
|
|
|
|
checkModel = function(model){
|
2015-06-01 23:22:49 +02:00
|
|
|
"Checking model class: Must be : train, RandomForest, randomForest"
|
2015-05-31 21:09:04 +02:00
|
|
|
if(!(inherits(model, "train") | inherits(model, "RandomForest") | inherits(model, "randomForest"))){
|
|
|
|
stop("Model is not recognized. Must be : train, RandomForest, randomForest")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getFullData = function(){
|
2015-06-01 23:22:49 +02:00
|
|
|
"Return twin1, twin2 and difft in column"
|
2015-05-31 21:09:04 +02:00
|
|
|
if(length(.self$twin1) != nrow(.self$vt.object$data)) stop("Twin1 must have same length as data")
|
|
|
|
if(length(.self$twin2) != nrow(.self$vt.object$data)) stop("Twin2 must have same length as data")
|
|
|
|
|
|
|
|
if(length(.self$difft) != nrow(.self$vt.object$data)) stop("Difft must have same length as data")
|
|
|
|
|
|
|
|
tmp <- cbind(.self$vt.object$data, .self$twin1, .self$twin2, .self$difft)
|
|
|
|
|
|
|
|
colnames(tmp) <- c(colnames(.self$vt.object$data), "twin1", "twin2", "difft")
|
|
|
|
|
|
|
|
return(tmp)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|