mirror of
https://github.com/prise6/aVirtualTwins.git
synced 2024-05-01 19:52:43 +02:00
Added description and roxygen comments
This commit is contained in:
parent
fd2f5a0008
commit
abfded6c96
|
@ -15,7 +15,7 @@ Suggests:
|
|||
randomForest,
|
||||
caret
|
||||
Depends:
|
||||
R (>= 3.2.0),
|
||||
R (>= 3.0.0),
|
||||
methods
|
||||
Collate:
|
||||
'VirtualTwins.R'
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
#'
|
||||
#' @return vector \eqn{E(Y=1)}
|
||||
#'
|
||||
#'
|
||||
#' @include setClass.R
|
||||
#' @importClassesFrom party RandomForest
|
||||
#'
|
||||
#' @name VT.predict
|
||||
#'
|
||||
setGeneric("VT.predict",
|
||||
function(rfor, newdata, type){standardGeneric("VT.predict")}
|
||||
)
|
||||
|
|
59
R/tree.R
59
R/tree.R
|
@ -1,17 +1,47 @@
|
|||
# TREES COMPUTATIONS ------------------------------------------------------
|
||||
#' Tree to find subgroup
|
||||
#'
|
||||
#' An abstract reference class to compute tree
|
||||
#'
|
||||
#' @include difft.R setClass.R
|
||||
#' \code{VT.tree.class} and \code{VT.tree.reg} are children of \code{VT.tree}.
|
||||
#' \code{VT.tree.class} and \code{VT.tree.reg} try to find a strong association
|
||||
#' between \code{difft} (in \code{VT.difft} object) and RCT variables.
|
||||
#'
|
||||
#' @field vt.difft VT.difft object
|
||||
#' @field outcome vector
|
||||
#' @field threshold numeric Threshold for difft (c)
|
||||
#' @field screening logical TRUE if using varimp (default is VT.object screening field)
|
||||
#' @field sens character Sens can be ">" (default) or "<". Meaning : difft > threshold or difft < threshold
|
||||
#' In \code{VT.tree.reg}, a regression tree is computed on \code{difft} values.
|
||||
#' Then, thanks to the \code{threshold} it flags leafs of the \code{tree} which
|
||||
#' are above the \code{threshold} (when \code{sens} is ">"). Or it flags leafs
|
||||
#' which are below the \code{threshold} (when \code{sens} = "<").
|
||||
#'
|
||||
#' In \code{VT.tree.class}, it first flags \code{difft} above or below
|
||||
#' (depending on the \code{sens}) the given \code{threshold}. Then a
|
||||
#' classification tree is computed to find which variables explain flagged
|
||||
#' \code{difft}.
|
||||
#'
|
||||
#' To sum up, \code{VT.tree} try to understand which variables are associated
|
||||
#' with a big change of \code{difft}.
|
||||
#'
|
||||
#' Results are shown with \code{getRules()} function. \code{only.leaf} parameter
|
||||
#' allows to obtain only the leaf of the \code{tree}. \code{only.fav} parameter
|
||||
#' select only favorable nodes. \code{tables} shows incidence table of the rule.
|
||||
#' \code{verbose} allow \code{getRules()} to be quiet. And \code{compete} show
|
||||
#' also rules with \code{maxcompete} competitors from the \code{tree}.
|
||||
#'
|
||||
#' @include difft.R setClass.R
|
||||
#'
|
||||
#' @field vt.difft \code{VT.difft} object
|
||||
#' @field outcome outcome vector from \code{rpart} function
|
||||
#' @field threshold numeric Threshold for difft calculation (c)
|
||||
#' @field screening Logical. TRUE if using varimp. Default is VT.object
|
||||
#' screening field
|
||||
#' @field sens character Sens can be ">" (default) or "<". Meaning :
|
||||
#' \code{difft} > \code{threshold} or \code{difft} < \code{threshold}
|
||||
#' @field name character Names of the tree
|
||||
#' @field tree rpart Rpart object to construct the tree
|
||||
#' @field Ahat vector Indicator of beglonging to Ahat
|
||||
#'
|
||||
#'
|
||||
#' @seealso \code{\link{VT.tree.reg}}, \code{\link{VT.tree.class}}
|
||||
#'
|
||||
#' @name VT.tree
|
||||
#'
|
||||
#' @import methods
|
||||
VT.tree <- setRefClass(
|
||||
Class = "VT.tree",
|
||||
|
@ -29,7 +59,7 @@ VT.tree <- setRefClass(
|
|||
),
|
||||
|
||||
methods = list(
|
||||
initialize = function(vt.difft = VT.difft(), threshold = 0.05, sens = ">", screening = NULL){
|
||||
initialize = function(vt.difft = VT.difft(), threshold = 0.05, sens = ">", screening = NULL){
|
||||
.self$vt.difft <- vt.difft
|
||||
|
||||
.self$threshold <- threshold
|
||||
|
@ -41,6 +71,7 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
getData = function(){
|
||||
"Return data used for tree computation"
|
||||
d <- .self$vt.difft$vt.object$data[, 3:ncol(.self$vt.difft$vt.object$data)]
|
||||
|
||||
if(.self$screening == T){
|
||||
|
@ -55,6 +86,7 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
computeNameOfTree = function(type){
|
||||
"return label of response variable of the tree"
|
||||
return(type)
|
||||
if(.self$threshold < 0 ){
|
||||
threshold.chr <- paste0("m", -.self$threshold)
|
||||
|
@ -66,11 +98,13 @@ VT.tree <- setRefClass(
|
|||
return(paste(type, tmp[1], tmp[2], sep = ""))
|
||||
},
|
||||
|
||||
run = function(){
|
||||
run = function(...){
|
||||
"Compute tree with rpart parameters"
|
||||
if(length(.self$vt.difft$difft) == 0) stop("VT.difft::difft is an empty vector")
|
||||
},
|
||||
|
||||
getInfos = function(){
|
||||
"Return infos about tree"
|
||||
cat("\n")
|
||||
cat(sprintf("Threshold = %0.4f", .self$threshold))
|
||||
cat("\n")
|
||||
|
@ -86,6 +120,7 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
getRules = function(only.leaf = F, only.fav = F, tables = T, verbose = T, compete = F){
|
||||
"Retrun subgroups discovered by the tree. See details."
|
||||
|
||||
# On crée le tableau des competitors
|
||||
if(isTRUE(compete))
|
||||
|
@ -226,6 +261,7 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
createCompetitors = function(){
|
||||
"Create competitors table"
|
||||
|
||||
fr <- .self$tree$frame
|
||||
fr <- fr[fr$var != "<leaf>",]
|
||||
|
@ -253,10 +289,12 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
getIncidences = function(rule, rr.snd = T){
|
||||
"Return incidence of the rule"
|
||||
return(VT.incidences(.self$vt.difft, rule, rr.snd))
|
||||
},
|
||||
|
||||
getAhatIncidence = function(){
|
||||
"Return Ahat incidence"
|
||||
if(sum(.self$Ahat)!=0){
|
||||
|
||||
table.inc <- VT.incidences(vt.object = .self$vt.difft$vt.object, select = .self$Ahat)
|
||||
|
@ -279,6 +317,7 @@ VT.tree <- setRefClass(
|
|||
},
|
||||
|
||||
getAhatQuality = function(){
|
||||
"Return Ahat quality"
|
||||
|
||||
resub <- vt.getQAOriginal(.self$Ahat, response = .self$vt.difft$vt.object$getY(), trt = .self$vt.difft$vt.object$data[, 2])
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
# VT.TREE.CLASS -----------------------------------------------------------
|
||||
|
||||
#' A reference class to compute subgroups by classifiation tree
|
||||
#' Classification tree to find subgroups
|
||||
#'
|
||||
#' See \code{\link{VT.tree}}
|
||||
#'
|
||||
#' @include tree.R
|
||||
#'
|
||||
#' @name VT.tree.class
|
||||
#'
|
||||
#' @import methods
|
||||
VT.tree.class <- setRefClass(
|
||||
Class = "VT.tree.class",
|
||||
|
@ -24,6 +28,7 @@ VT.tree.class <- setRefClass(
|
|||
},
|
||||
|
||||
run = function(...){
|
||||
"VT.tree.class:run(...) Compute classification tree with rpart parameters"
|
||||
callSuper()
|
||||
|
||||
data <- .self$getData()
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
# VT.TREE.REG -------------------------------------------------------------
|
||||
|
||||
#' Regression tree to find subgroups
|
||||
#'
|
||||
#' See \code{\link{VT.tree}}
|
||||
#'
|
||||
#' @include tree.R
|
||||
#' A reference class to compute subgroups by regression tree with rpart package
|
||||
#'
|
||||
#' @name VT.tree.reg
|
||||
|
||||
VT.tree.reg <- setRefClass(
|
||||
Class = "VT.tree.reg",
|
||||
|
@ -20,7 +24,6 @@ VT.tree.reg <- setRefClass(
|
|||
|
||||
run = function(...){
|
||||
callSuper()
|
||||
|
||||
data <- .self$getData()
|
||||
|
||||
.self$tree <- rpart::rpart(as.formula(paste(.self$name, ".", sep = "~")), data = data, ...)
|
||||
|
|
|
@ -20,7 +20,7 @@ favorable outcome is 1. Then, \deqn{difft_i = twin1_i - twin2_i IF T_i =
|
|||
|
||||
\item{\code{twin1}}{vector of \eqn{E(Y|T = real treatment)}}
|
||||
|
||||
\item{\code{twin2}}{vector of \eqn{E(Y|T = anoher treatment)}}
|
||||
\item{\code{twin2}}{vector of \eqn{E(Y|T = another treatment)}}
|
||||
|
||||
\item{\code{difft}}{vector of difference between twin1 and twin2}
|
||||
}}
|
||||
|
|
|
@ -22,7 +22,7 @@ An abstract reference class to compute twin via random forests
|
|||
|
||||
\item{\code{getFullData()}}{Return twin1, twin2 and difft in column}
|
||||
|
||||
\item{\code{run()}}{Compute twin1 and twin2 computation. Switch treatment if necessary.}
|
||||
\item{\code{run()}}{Compute twin1 and twin2 estimation. Switch treatment if necessary.}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest.one}}, \code{\link{VT.forest.double}}
|
||||
|
|
|
@ -31,7 +31,7 @@ interactions}
|
|||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{run()}}{Compute twin1 and twin2 computation. Switch treatment if necessary.}
|
||||
\item{\code{run()}}{Compute twin1 and twin2 estimation. Switch treatment if necessary.}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.difft}}, \code{\link{VT.forest}},
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/tree.R
|
||||
\docType{class}
|
||||
\name{VT.tree-class}
|
||||
\alias{VT.tree}
|
||||
\alias{VT.tree-class}
|
||||
\title{An abstract reference class to compute tree}
|
||||
\description{
|
||||
An abstract reference class to compute tree
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{vt.difft}}{VT.difft object}
|
||||
|
||||
\item{\code{outcome}}{vector}
|
||||
|
||||
\item{\code{threshold}}{numeric Threshold for difft (c)}
|
||||
|
||||
\item{\code{screening}}{logical TRUE if using varimp (default is VT.object screening field)}
|
||||
|
||||
\item{\code{sens}}{character Sens can be ">" (default) or "<". Meaning : difft > threshold or difft < threshold}
|
||||
|
||||
\item{\code{name}}{character Names of the tree}
|
||||
|
||||
\item{\code{tree}}{rpart Rpart object to construct the tree}
|
||||
|
||||
\item{\code{Ahat}}{vector Indicator of beglonging to Ahat}
|
||||
}}
|
||||
|
80
man/VT.tree.Rd
Normal file
80
man/VT.tree.Rd
Normal file
|
@ -0,0 +1,80 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/tree.R
|
||||
\docType{class}
|
||||
\name{VT.tree}
|
||||
\alias{VT.tree}
|
||||
\title{Tree to find subgroup}
|
||||
\description{
|
||||
An abstract reference class to compute tree
|
||||
}
|
||||
\details{
|
||||
\code{VT.tree.class} and \code{VT.tree.reg} are children of \code{VT.tree}.
|
||||
\code{VT.tree.class} and \code{VT.tree.reg} try to find a strong association
|
||||
between \code{difft} (in \code{VT.difft} object) and RCT variables.
|
||||
|
||||
In \code{VT.tree.reg}, a regression tree is computed on \code{difft} values.
|
||||
Then, thanks to the \code{threshold} it flags leafs of the \code{tree} which
|
||||
are above the \code{threshold} (when \code{sens} is ">"). Or it flags leafs
|
||||
which are below the \code{threshold} (when \code{sens} = "<").
|
||||
|
||||
In \code{VT.tree.class}, it first flags \code{difft} above or below
|
||||
(depending on the \code{sens}) the given \code{threshold}. Then a
|
||||
classification tree is computed to find which variables explain flagged
|
||||
\code{difft}.
|
||||
|
||||
To sum up, \code{VT.tree} try to understand which variables are associated
|
||||
with a big change of \code{difft}.
|
||||
|
||||
Results are shown with \code{getRules()} function. \code{only.leaf} parameter
|
||||
allows to obtain only the leaf of the \code{tree}. \code{only.fav} parameter
|
||||
select only favorable nodes. \code{tables} shows incidence table of the rule.
|
||||
\code{verbose} allow \code{getRules()} to be quiet. And \code{compete} show
|
||||
also rules with \code{maxcompete} competitors from the \code{tree}.
|
||||
}
|
||||
\section{Fields}{
|
||||
|
||||
\describe{
|
||||
\item{\code{vt.difft}}{\code{VT.difft} object}
|
||||
|
||||
\item{\code{outcome}}{outcome vector from \code{rpart} function}
|
||||
|
||||
\item{\code{threshold}}{numeric Threshold for difft calculation (c)}
|
||||
|
||||
\item{\code{screening}}{Logical. TRUE if using varimp. Default is VT.object
|
||||
screening field}
|
||||
|
||||
\item{\code{sens}}{character Sens can be ">" (default) or "<". Meaning :
|
||||
\code{difft} > \code{threshold} or \code{difft} < \code{threshold}}
|
||||
|
||||
\item{\code{name}}{character Names of the tree}
|
||||
|
||||
\item{\code{tree}}{rpart Rpart object to construct the tree}
|
||||
|
||||
\item{\code{Ahat}}{vector Indicator of beglonging to Ahat}
|
||||
}}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{computeNameOfTree(type)}}{return label of response variable of the tree}
|
||||
|
||||
\item{\code{createCompetitors()}}{Create competitors table}
|
||||
|
||||
\item{\code{getAhatIncidence()}}{Return Ahat incidence}
|
||||
|
||||
\item{\code{getAhatQuality()}}{Return Ahat quality}
|
||||
|
||||
\item{\code{getData()}}{Return data used for tree computation}
|
||||
|
||||
\item{\code{getIncidences(rule, rr.snd = T)}}{Return incidence of the rule}
|
||||
|
||||
\item{\code{getInfos()}}{Return infos about tree}
|
||||
|
||||
\item{\code{getRules(only.leaf = F, only.fav = F, tables = T, verbose = T,
|
||||
compete = F)}}{Retrun subgroups discovered by the tree. See details.}
|
||||
|
||||
\item{\code{run(...)}}{Compute tree with rpart parameters}
|
||||
}}
|
||||
\seealso{
|
||||
\code{\link{VT.tree.reg}}, \code{\link{VT.tree.class}}
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/tree.class.R
|
||||
\docType{class}
|
||||
\name{VT.tree.class-class}
|
||||
\alias{VT.tree.class}
|
||||
\alias{VT.tree.class-class}
|
||||
\title{A reference class to compute subgroups by classifiation tree}
|
||||
\description{
|
||||
A reference class to compute subgroups by classifiation tree
|
||||
}
|
||||
|
15
man/VT.tree.class.Rd
Normal file
15
man/VT.tree.class.Rd
Normal file
|
@ -0,0 +1,15 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/tree.class.R
|
||||
\docType{class}
|
||||
\name{VT.tree.class}
|
||||
\alias{VT.tree.class}
|
||||
\title{Classification tree to find subgroups}
|
||||
\description{
|
||||
See \code{\link{VT.tree}}
|
||||
}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{run(...)}}{Compute tree with rpart parameters}
|
||||
}}
|
||||
|
15
man/VT.tree.reg.Rd
Normal file
15
man/VT.tree.reg.Rd
Normal file
|
@ -0,0 +1,15 @@
|
|||
% Generated by roxygen2 (4.1.1): do not edit by hand
|
||||
% Please edit documentation in R/tree.reg.R
|
||||
\docType{class}
|
||||
\name{VT.tree.reg}
|
||||
\alias{VT.tree.reg}
|
||||
\title{Regression tree to find subgroups}
|
||||
\description{
|
||||
See \code{\link{VT.tree}}
|
||||
}
|
||||
\section{Methods}{
|
||||
|
||||
\describe{
|
||||
\item{\code{run(...)}}{Compute tree with rpart parameters}
|
||||
}}
|
||||
|
Loading…
Reference in a new issue