2015-05-31 21:09:04 +02:00
|
|
|
# VT.FOREST.DOUBLE --------------------------------------------------------
|
|
|
|
# IF RUNNING DOUBLE FOREST COMPUTATION
|
|
|
|
|
2015-06-10 16:48:18 +02:00
|
|
|
#' Difft by double random forest
|
|
|
|
#'
|
2015-06-01 23:22:49 +02:00
|
|
|
#' A reference class to compute twins via double random forests
|
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' \code{VT.forest.double} extends \code{VT.forest}.
|
2015-06-01 23:22:49 +02:00
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' \eqn{E(Y|T = 1)} if \eqn{T_i = 1} is estimated by OOB predictions from
|
|
|
|
#' \code{model_trt1}.
|
|
|
|
#' \eqn{E(Y|T = 0)} if \eqn{T_i = 0} is estimated by OOB predictions from
|
|
|
|
#' \code{model_trt0}.
|
|
|
|
#' This is what \code{computeTwin1()} does.
|
2015-06-01 23:22:49 +02:00
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' Then \eqn{E(Y|T = 1)} if \eqn{T_i = 0} is estimated by model_trt1.
|
|
|
|
#' Then \eqn{E(Y|T = 0)} if \eqn{T_i = 1} is estimated by model_trt1.
|
|
|
|
#' This is what \code{computeTwin2()} does.
|
|
|
|
#'
|
|
|
|
#' @include forest.R
|
|
|
|
#'
|
|
|
|
#' @field model_trt1 a caret/RandomForest/randomForest object for treatment T =
|
|
|
|
#' 1
|
|
|
|
#' @field model_trt0 a caret/RandomForest/randomForest object for treatment T =
|
|
|
|
#' 0
|
2015-06-11 13:34:55 +02:00
|
|
|
#' @field ... field from parent class : \code{\link{VT.forest}}
|
2015-06-10 16:48:18 +02:00
|
|
|
#'
|
|
|
|
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest}},
|
|
|
|
#' \code{\link{VT.forest.one}}
|
|
|
|
#'
|
2015-06-11 13:34:55 +02:00
|
|
|
#' @export VT.forest.double
|
|
|
|
#'
|
2015-06-10 16:48:18 +02:00
|
|
|
#' @name VT.forest.double
|
|
|
|
#'
|
2015-06-01 23:22:49 +02:00
|
|
|
#' @import methods
|
2015-05-31 21:09:04 +02:00
|
|
|
VT.forest.double <- setRefClass(
|
|
|
|
Class = "VT.forest.double",
|
|
|
|
|
|
|
|
contains = "VT.forest",
|
|
|
|
|
|
|
|
fields = list(
|
|
|
|
model_trt1 = "ANY",
|
|
|
|
model_trt0 = "ANY"
|
|
|
|
),
|
|
|
|
|
|
|
|
methods = list(
|
|
|
|
initialize = function(vt.object, model_trt1, model_trt0, ...){
|
|
|
|
.self$checkModel(model_trt1)
|
|
|
|
.self$checkModel(model_trt0)
|
|
|
|
|
|
|
|
.self$model_trt1 <- model_trt1
|
|
|
|
.self$model_trt0 <- model_trt0
|
|
|
|
|
|
|
|
callSuper(vt.object, ...)
|
|
|
|
},
|
|
|
|
|
|
|
|
computeTwin1 = function(){
|
2015-06-10 16:48:18 +02:00
|
|
|
"Compute twin1 with OOB predictions from double forests. See details."
|
2015-05-31 21:09:04 +02:00
|
|
|
# Model with treatment (1)
|
|
|
|
.self$twin1[.self$vt.object$data[, 2] == 1] <- VT.predict(rfor = .self$model_trt1, type = .self$vt.object$type)
|
|
|
|
|
|
|
|
# Model without treatment (0)
|
|
|
|
.self$twin1[vt.object$data[, 2] == 0] <- VT.predict(rfor = .self$model_trt0, type = .self$vt.object$type)
|
|
|
|
return(.self$twin1)
|
|
|
|
return(invisible(.self$twin1))
|
|
|
|
},
|
|
|
|
|
|
|
|
computeTwin2 = function(){
|
2015-06-10 16:48:18 +02:00
|
|
|
"Compute twin2 by the other part of data in the other forest. See details."
|
2015-05-31 21:09:04 +02:00
|
|
|
# Model with treatment (1)
|
|
|
|
.self$twin2[.self$vt.object$data[, 2] == 1] <- VT.predict(.self$model_trt0, newdata = .self$vt.object$getX(1, interactions = F), type = .self$vt.object$type)
|
|
|
|
|
|
|
|
# Model without treatment (0)
|
|
|
|
.self$twin2[.self$vt.object$data[, 2] == 0] <- VT.predict(.self$model_trt1, newdata = .self$vt.object$getX(0, interactions = F), type = .self$vt.object$type)
|
|
|
|
return(invisible(.self$twin2))
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|