mirror of
https://github.com/prise6/aVirtualTwins.git
synced 2024-05-01 19:52:43 +02:00
Add documentation about forests
This commit is contained in:
parent
f00b8835ee
commit
fd2f5a0008
|
@ -12,7 +12,7 @@
|
|||
#'
|
||||
#' @field vt.object VT.object (refClass) representing data
|
||||
#' @field twin1 vector of \eqn{E(Y|T = real treatment)}
|
||||
#' @field twin2 vector of \eqn{E(Y|T = anoher treatment)}
|
||||
#' @field twin2 vector of \eqn{E(Y|T = another treatment)}
|
||||
#' @field difft vector of difference between twin1 and twin2
|
||||
#'
|
||||
#' @name VT.difft
|
||||
|
|
16
R/forest.R
16
R/forest.R
|
@ -1,10 +1,20 @@
|
|||
# FORESTS -----------------------------------------------------------------
|
||||
|
||||
#' A abstract reference class to compute twin via random forests
|
||||
#' Difft by Random Forest
|
||||
#'
|
||||
#' An abstract reference class to compute twin via random forests
|
||||
#'
|
||||
#' \code{VT.forest} extends \code{VT.difft}
|
||||
#'
|
||||
#' @field ... see fields of \linkS4class{VT.difft}
|
||||
#'
|
||||
#' @include difft.R predict.R
|
||||
#'
|
||||
#' @name VT.forest
|
||||
#'
|
||||
#' @import methods
|
||||
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
||||
#'
|
||||
#' @import methods
|
||||
VT.forest <- setRefClass(
|
||||
Class = "VT.forest",
|
||||
|
||||
|
@ -12,7 +22,7 @@ VT.forest <- setRefClass(
|
|||
|
||||
methods = list(
|
||||
run = function(){
|
||||
"Compute twin1 and twin2 computation. Switch treatment if necessary."
|
||||
"Compute twin1 and twin2 estimation. Switch treatment if necessary."
|
||||
.self$computeTwin1()
|
||||
|
||||
if(inherits(.self, "VT.forest.one")) .self$vt.object$switchTreatment() #if one forest
|
||||
|
|
|
@ -1,13 +1,35 @@
|
|||
# VT.FOREST.DOUBLE --------------------------------------------------------
|
||||
# IF RUNNING DOUBLE FOREST COMPUTATION
|
||||
|
||||
#' Difft by double random forest
|
||||
#'
|
||||
#' A reference class to compute twins via double random forests
|
||||
#'
|
||||
#' \code{VT.forest.double} extends \code{VT.forest}.
|
||||
#'
|
||||
#' \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.
|
||||
#'
|
||||
#' 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
|
||||
#'
|
||||
#'
|
||||
#' @field model_trt1 a caret/RandomForest/randomForest object for treatment T =
|
||||
#' 1
|
||||
#' @field model_trt0 a caret/RandomForest/randomForest object for treatment T =
|
||||
#' 0
|
||||
#' @field ... field from parent class : \linkS4class{VT.forest}
|
||||
#'
|
||||
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest}},
|
||||
#' \code{\link{VT.forest.one}}
|
||||
#'
|
||||
#' @name VT.forest.double
|
||||
#'
|
||||
#' @import methods
|
||||
VT.forest.double <- setRefClass(
|
||||
Class = "VT.forest.double",
|
||||
|
@ -31,7 +53,7 @@ VT.forest.double <- setRefClass(
|
|||
},
|
||||
|
||||
computeTwin1 = function(){
|
||||
"Compute twin1 with OOB predictions from double forests"
|
||||
"Compute twin1 with OOB predictions from double forests. See details."
|
||||
# Model with treatment (1)
|
||||
.self$twin1[.self$vt.object$data[, 2] == 1] <- VT.predict(rfor = .self$model_trt1, type = .self$vt.object$type)
|
||||
|
||||
|
@ -42,7 +64,7 @@ VT.forest.double <- setRefClass(
|
|||
},
|
||||
|
||||
computeTwin2 = function(){
|
||||
"Compute twin2 by the other part of data in the other forest"
|
||||
"Compute twin2 by the other part of data in the other forest. See details."
|
||||
# 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)
|
||||
|
||||
|
|
|
@ -1,14 +1,29 @@
|
|||
# VT.FOREST.FOLD ----------------------------------------------------------
|
||||
|
||||
#' Difft via k random forests
|
||||
#'
|
||||
#' A reference class to compute twins via k random forest
|
||||
#'
|
||||
#' \code{VT.forest.fold} extends \code{VT.forest}
|
||||
#'
|
||||
#' Twins are estimated by k-fold cross validation. A forest is computed on k-1/k
|
||||
#' of the data and then used to estimate twin1 and twin2 on 1/k of the left
|
||||
#' data.
|
||||
#'
|
||||
#' @include forest.R
|
||||
#'
|
||||
#' @field interactions logical set TRUE if model has been computed with interactions
|
||||
#' @field fold numeric Number of fold, i.e. number of forest
|
||||
#' @field ratio numeric
|
||||
#' @field groups vector Define which observations belong to which group
|
||||
#'
|
||||
#'
|
||||
#' @field interactions logical set TRUE if model has been computed with
|
||||
#' interactions
|
||||
#' @field fold numeric, number of fold, i.e. number of forest (k)
|
||||
#' @field ratio numeric experimental, use to balance sampsize. Defaut to 1.
|
||||
#' @field groups vector Define which observations belong to which group
|
||||
#' @field ... field from parent class : \linkS4class{VT.forest}
|
||||
#'
|
||||
#' @name VT.forest.fold
|
||||
#'
|
||||
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest}},
|
||||
#' \code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
||||
#'
|
||||
#' @import methods
|
||||
VT.forest.fold <- setRefClass(
|
||||
Class = "VT.forest.fold",
|
||||
|
@ -59,6 +74,7 @@ VT.forest.fold <- setRefClass(
|
|||
samp2 <- Yeff[2]
|
||||
samp1 <- sampmin
|
||||
}
|
||||
if(!requireNamespace("randomForest", quietly = TRUE)) stop("randomForest package must be loaded.")
|
||||
rf <- randomForest(x = X, y = Y, sampsize = c(samp1, samp2), keep.forest = T, ...)
|
||||
|
||||
.self$computeTwin1(rf, group)
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
# VT.FOREST.ONE -----------------------------------------------------------
|
||||
# IF RUNNING ONE FOREST COMPUTATION
|
||||
|
||||
#' Difft by one random forest
|
||||
#'
|
||||
#' A reference class to compute twins via one random forest
|
||||
#'
|
||||
#' \code{VT.forest.one} extends \code{VT.forest}.
|
||||
#'
|
||||
#' OOB predictions are used to estimate \eqn{E(Y|T = real treatment)}. Then,
|
||||
#' treatement is switched, it means that 1 becomes 0 and 0 becomes 1. We use
|
||||
#' again \code{model} to estimate \eqn{E(Y|T = the other treatment)}. This is
|
||||
#' what \code{computeTwin1()} and \code{computeTwin2()} functions do.
|
||||
#'
|
||||
#' @include forest.R
|
||||
#'
|
||||
#' @field model ANY a caret/RandomForest/randomForest class object
|
||||
#' @field model is 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
|
||||
#' @field ... field from parent class : \linkS4class{VT.forest}
|
||||
#'
|
||||
#' @seealso \code{\link{VT.difft}}, \code{\link{VT.forest}}, \code{\link{VT.forest.double}}
|
||||
#'
|
||||
#' @name VT.forest.one
|
||||
#'
|
||||
#' @import methods
|
||||
VT.forest.one <- setRefClass(
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.R
|
||||
\docType{class}
|
||||
\name{VT.forest-class}
|
||||
\name{VT.forest}
|
||||
\alias{VT.forest}
|
||||
\alias{VT.forest-class}
|
||||
\title{A abstract reference class to compute twin via random forests}
|
||||
\title{Difft by Random Forest}
|
||||
\description{
|
||||
A abstract reference class to compute twin via random forests
|
||||
An abstract reference class to compute twin via random forests
|
||||
}
|
||||
\details{
|
||||
\code{VT.forest} extends \code{VT.difft}
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{...}}{see fields of \linkS4class{VT.difft}}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
|
@ -17,4 +24,7 @@ A abstract reference class to compute twin via random forests
|
|||
|
||||
\item{\code{run()}}{Compute twin1 and twin2 computation. Switch treatment if necessary.}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.double.R
|
||||
\docType{class}
|
||||
\name{VT.forest.double-class}
|
||||
\alias{VT.forest.double}
|
||||
\alias{VT.forest.double-class}
|
||||
\title{A reference class to compute twins via double random forests}
|
||||
\description{
|
||||
A reference class to compute twins via double random forests
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{model_trt1}}{a caret/RandomForest/randomForest object for treatment T = 1}
|
||||
|
||||
\item{\code{model_trt0}}{a caret/RandomForest/randomForest object for treatment T = 0}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{computeTwin1()}}{Compute twin1 with OOB predictions from double forests}
|
||||
|
||||
\item{\code{computeTwin2()}}{Compute twin2 by the other part of data in the other forest}
|
||||
}}
|
||||
|
45
man/VT.forest.double.Rd
Normal file
45
man/VT.forest.double.Rd
Normal file
|
@ -0,0 +1,45 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.double.R
|
||||
\docType{class}
|
||||
\name{VT.forest.double}
|
||||
\alias{VT.forest.double}
|
||||
\title{Difft by double random forest}
|
||||
\description{
|
||||
A reference class to compute twins via double random forests
|
||||
}
|
||||
\details{
|
||||
\code{VT.forest.double} extends \code{VT.forest}.
|
||||
|
||||
\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.
|
||||
|
||||
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.
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{model_trt1}}{a caret/RandomForest/randomForest object for treatment T =
|
||||
1}
|
||||
|
||||
\item{\code{model_trt0}}{a caret/RandomForest/randomForest object for treatment T =
|
||||
0}
|
||||
|
||||
\item{\code{...}}{field from parent class : \linkS4class{VT.forest}}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{computeTwin1()}}{Compute twin1 with OOB predictions from double forests. See details.}
|
||||
|
||||
\item{\code{computeTwin2()}}{Compute twin2 by the other part of data in the other forest. See details.}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest}},
|
||||
\code{\link{VT.forest.one}}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.fold.R
|
||||
\docType{class}
|
||||
\name{VT.forest.fold-class}
|
||||
\alias{VT.forest.fold}
|
||||
\alias{VT.forest.fold-class}
|
||||
\title{A reference class to compute twins via k random forest}
|
||||
\description{
|
||||
A reference class to compute twins via k random forest
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{interactions}}{logical set TRUE if model has been computed with interactions}
|
||||
|
||||
\item{\code{fold}}{numeric Number of fold, i.e. number of forest}
|
||||
|
||||
\item{\code{ratio}}{numeric}
|
||||
|
||||
\item{\code{groups}}{vector Define which observations belong to which group}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{run()}}{Compute twin1 and twin2 computation. Switch treatment if necessary.}
|
||||
}}
|
||||
|
40
man/VT.forest.fold.Rd
Normal file
40
man/VT.forest.fold.Rd
Normal file
|
@ -0,0 +1,40 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.fold.R
|
||||
\docType{class}
|
||||
\name{VT.forest.fold}
|
||||
\alias{VT.forest.fold}
|
||||
\title{Difft via k random forests}
|
||||
\description{
|
||||
A reference class to compute twins via k random forest
|
||||
}
|
||||
\details{
|
||||
\code{VT.forest.fold} extends \code{VT.forest}
|
||||
|
||||
Twins are estimated by k-fold cross validation. A forest is computed on k-1/k
|
||||
of the data and then used to estimate twin1 and twin2 on 1/k of the left
|
||||
data.
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{interactions}}{logical set TRUE if model has been computed with
|
||||
interactions}
|
||||
|
||||
\item{\code{fold}}{numeric, number of fold, i.e. number of forest (k)}
|
||||
|
||||
\item{\code{ratio}}{numeric experimental, use to balance sampsize. Defaut to 1.}
|
||||
|
||||
\item{\code{groups}}{vector Define which observations belong to which group}
|
||||
|
||||
\item{\code{...}}{field from parent class : \linkS4class{VT.forest}}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{run()}}{Compute twin1 and twin2 computation. Switch treatment if necessary.}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest}},
|
||||
\code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.one.R
|
||||
\docType{class}
|
||||
\name{VT.forest.one-class}
|
||||
\alias{VT.forest.one}
|
||||
\alias{VT.forest.one-class}
|
||||
\title{A reference class to compute twins via one random forest}
|
||||
\description{
|
||||
A reference class to compute twins via one random forest
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{model}}{ANY a caret/RandomForest/randomForest class object}
|
||||
|
||||
\item{\code{interactions}}{logical set TRUE if model has been computed with interactions}
|
||||
|
||||
\item{\code{...}}{field from parent class : VT.forest}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{computeTwin1()}}{Compute twin1 with OOB predictions}
|
||||
|
||||
\item{\code{computeTwin2()}}{Compute twin2 by switching treatment and applying random forest model}
|
||||
}}
|
||||
|
37
man/VT.forest.one.Rd
Normal file
37
man/VT.forest.one.Rd
Normal file
|
@ -0,0 +1,37 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/forest.one.R
|
||||
\docType{class}
|
||||
\name{VT.forest.one}
|
||||
\alias{VT.forest.one}
|
||||
\title{Difft by one random forest}
|
||||
\description{
|
||||
A reference class to compute twins via one random forest
|
||||
}
|
||||
\details{
|
||||
\code{VT.forest.one} extends \code{VT.forest}.
|
||||
|
||||
OOB predictions are used to estimate \eqn{E(Y|T = real treatment)}. Then,
|
||||
treatement is switched, it means that 1 becomes 0 and 0 becomes 1. We use
|
||||
again \code{model} to estimate \eqn{E(Y|T = the other treatment)}. This is
|
||||
what \code{computeTwin1()} and \code{computeTwin2()} functions do.
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{model}}{is a caret/RandomForest/randomForest class object}
|
||||
|
||||
\item{\code{interactions}}{logical set TRUE if model has been computed with interactions}
|
||||
|
||||
\item{\code{...}}{field from parent class : \linkS4class{VT.forest}}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{computeTwin1()}}{Compute twin1 with OOB predictions}
|
||||
|
||||
\item{\code{computeTwin2()}}{Compute twin2 by switching treatment and applying random forest model}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest}}, \code{\link{VT.forest.double}}
|
||||
}
|
||||
|
Loading…
Reference in a new issue