2015-05-31 21:09:04 +02:00
|
|
|
# VT.FOREST.ONE -----------------------------------------------------------
|
|
|
|
# IF RUNNING ONE FOREST COMPUTATION
|
2015-06-01 23:22:49 +02:00
|
|
|
|
|
|
|
#' A reference class to compute twins via one random forest
|
|
|
|
#'
|
|
|
|
#' @include forest.R
|
|
|
|
#'
|
|
|
|
#' @field model ANY a caret/RandomForest/randomForest class object
|
|
|
|
#' @field interactions logical set TRUE if model has been computed with interactions
|
|
|
|
#' @field ... field from parent class : VT.forest
|
|
|
|
#'
|
|
|
|
#' @import methods
|
2015-05-31 21:09:04 +02:00
|
|
|
VT.forest.one <- setRefClass(
|
|
|
|
Class = "VT.forest.one",
|
|
|
|
|
|
|
|
contains = "VT.forest",
|
|
|
|
|
|
|
|
fields = list(
|
|
|
|
model = "ANY",
|
|
|
|
interactions = "logical"
|
|
|
|
),
|
|
|
|
|
|
|
|
methods = list(
|
|
|
|
initialize = function(vt.object, model, interactions = T, ...){
|
|
|
|
.self$checkModel(model)
|
|
|
|
|
|
|
|
.self$model <- model
|
|
|
|
|
|
|
|
.self$interactions <- interactions
|
|
|
|
|
|
|
|
callSuper(vt.object, ...)
|
|
|
|
},
|
|
|
|
|
|
|
|
computeTwin1 = function(){
|
2015-06-01 23:22:49 +02:00
|
|
|
"Compute twin1 with OOB predictions"
|
2015-05-31 21:09:04 +02:00
|
|
|
.self$twin1 <- as.vector(VT.predict(rfor = .self$model, type = .self$vt.object$type))
|
|
|
|
return(invisible(.self$twin1))
|
|
|
|
},
|
|
|
|
|
|
|
|
computeTwin2 = function(){
|
2015-06-01 23:22:49 +02:00
|
|
|
"Compute twin2 by switching treatment and applying random forest model"
|
2015-05-31 21:09:04 +02:00
|
|
|
.self$twin2 <- as.vector(VT.predict(.self$model,
|
|
|
|
newdata = .self$vt.object$getX(interactions = .self$interactions),
|
|
|
|
.self$vt.object$type))
|
|
|
|
return(invisible(.self$twin2))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|