diff --git a/DESCRIPTION b/DESCRIPTION index 92c2ebe..948b9c9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,7 @@ Suggests: randomForest, caret Depends: - R (>= 3.2.0), + R (>= 3.0.0), methods Collate: 'VirtualTwins.R' diff --git a/R/predict.R b/R/predict.R index b42d233..76d4bfd 100644 --- a/R/predict.R +++ b/R/predict.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")} ) diff --git a/R/tree.R b/R/tree.R index 58ae35d..c655c43 100644 --- a/R/tree.R +++ b/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 != "",] @@ -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]) diff --git a/R/tree.class.R b/R/tree.class.R index 0700a7c..37fb844 100644 --- a/R/tree.class.R +++ b/R/tree.class.R @@ -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() diff --git a/R/tree.reg.R b/R/tree.reg.R index 1893d72..d7dde60 100644 --- a/R/tree.reg.R +++ b/R/tree.reg.R @@ -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, ...) diff --git a/man/VT.difft.Rd b/man/VT.difft.Rd index 1320639..4b36f71 100644 --- a/man/VT.difft.Rd +++ b/man/VT.difft.Rd @@ -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} }} diff --git a/man/VT.forest.Rd b/man/VT.forest.Rd index c6e832f..65a2eff 100644 --- a/man/VT.forest.Rd +++ b/man/VT.forest.Rd @@ -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}} diff --git a/man/VT.forest.fold.Rd b/man/VT.forest.fold.Rd index 07cdea6..753492b 100644 --- a/man/VT.forest.fold.Rd +++ b/man/VT.forest.fold.Rd @@ -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}}, diff --git a/man/VT.tree-class.Rd b/man/VT.tree-class.Rd deleted file mode 100644 index ec4b9de..0000000 --- a/man/VT.tree-class.Rd +++ /dev/null @@ -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} -}} - diff --git a/man/VT.tree.Rd b/man/VT.tree.Rd new file mode 100644 index 0000000..7fe0bb4 --- /dev/null +++ b/man/VT.tree.Rd @@ -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}} +} + diff --git a/man/VT.tree.class-class.Rd b/man/VT.tree.class-class.Rd deleted file mode 100644 index fcb45ba..0000000 --- a/man/VT.tree.class-class.Rd +++ /dev/null @@ -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 -} - diff --git a/man/VT.tree.class.Rd b/man/VT.tree.class.Rd new file mode 100644 index 0000000..3f3939d --- /dev/null +++ b/man/VT.tree.class.Rd @@ -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} +}} + diff --git a/man/VT.tree.reg.Rd b/man/VT.tree.reg.Rd new file mode 100644 index 0000000..8485e61 --- /dev/null +++ b/man/VT.tree.reg.Rd @@ -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} +}} +