diff --git a/inst/doc/full-example.R b/inst/doc/full-example.R index a5a4067..a2dee91 100644 --- a/inst/doc/full-example.R +++ b/inst/doc/full-example.R @@ -116,7 +116,10 @@ head(model.difft$difft) tr.class <- vt.tree("class", vt.difft = vt.f.rf, sens = ">", - threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1))) + threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1)), + maxdepth = 3, + cp = 0, + maxcompete = 2) # tr.class is a list if threshold is a vectoor class(tr.class) # acce trees with treeXX @@ -130,6 +133,34 @@ tr.reg <- vt.tree("reg", threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1))) # tr.class is a list if threshold is a vectoor class(tr.reg) -# acce trees with treeXX +# access trees with treeXX class(tr.reg$tree1) +## ------------------------------------------------------------------------ +# use tr.class computed previously +vt.sbgrps <- vt.subgroups(tr.class) +# print tables with knitr package +library(knitr) +knitr::kable(vt.sbgrps) + +## ---- echo=F, fig.align='center', fig.height=4, fig.width=6-------------- +library(rpart.plot) +rpart.plot(tr.class$tree2$tree, type = 1, extra = 1) + +## ------------------------------------------------------------------------ +tr.class$tree2$createCompetitors() +head(tr.class$tree2$competitors) + +## ------------------------------------------------------------------------ +vt.o$getIncidences("PRAPACHE >= 26 & AGE >= 52") +# or +# tr.class$tree2$getIncidences("PRAPACHE >= 26 & AGE >= 52") + +## ------------------------------------------------------------------------ +tr.class$tree2$getInfos() +# access Ahat +# tr.class$tree2$Ahat + +## ------------------------------------------------------------------------ +tr.class$tree2$run(maxdepth = 2) + diff --git a/inst/doc/full-example.Rmd b/inst/doc/full-example.Rmd index 33a3f15..aa2d70f 100644 --- a/inst/doc/full-example.Rmd +++ b/inst/doc/full-example.Rmd @@ -10,6 +10,18 @@ vignette: > %\VignetteEncoding{UTF-8} --- +# Contents + +1. Introduction +2. Quick preview +3. Sepsis dataset +4. Create object virtual twins +5. Step 1 : compute probabilities +6. Step 2 : Estimate a decision tree +7. Subgroups and results +8. Questions + + # Introduction The goal of this vignette is to show most of all possibilies with *aVT* (for *aVirtualTwins* meaning *a*daptation of *Virtual Twins* method) package. @@ -310,7 +322,7 @@ Anyway, aVirtualTwins package can be used. To do so, you can use `VT.difft()` cl * `vt.object` : return of `vt.data()` function * `twin1` : estimate of $P(Y_{i} = 1 | T = T_{i})$ : meaning response probability under the correct treatment. -* `twin1` : estimate of $P(Y_{i} = 1 | T = 1-T_{i})$ : meaning response probability under the other treatment. +* `twin2` : estimate of $P(Y_{i} = 1 | T = 1-T_{i})$ : meaning response probability under the other treatment. * `method` : _absolute_ (default), _relative_ or _logit_. See `?VT.difft` for details. ```{r} @@ -360,7 +372,10 @@ See `?VT.tree` for details. tr.class <- vt.tree("class", vt.difft = vt.f.rf, sens = ">", - threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1))) + threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1)), + maxdepth = 3, + cp = 0, + maxcompete = 2) # tr.class is a list if threshold is a vectoor class(tr.class) # acce trees with treeXX @@ -382,13 +397,80 @@ tr.reg <- vt.tree("reg", threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1))) # tr.class is a list if threshold is a vectoor class(tr.reg) -# acce trees with treeXX +# access trees with treeXX class(tr.reg$tree1) ``` +----------- -## Subgroups and results - +# Subgroups and results + +Once trees have been computed, you surely want to see what are the subgroups. This package provides a wrapper function of intern methods of `VT.tree` class : `vt.subgroups()`. + +This function takes in argument : + +* `vt.tree` : object or list of class `VT.tree`. Return of the `vt.tree()` function. +* `only.leaf` : logical. Set `TRUE` (default) to visualize only terminal nodes. +* `only.fav` : logical. Set `TRUE` (default) to visualize only class 1 nodes. ($\hat{A}$) +* `tables` : logical. Set `FALSE` (default) to prevent tables of incidences from being printed. +* `verbose` : logical. Set `FALSE` (default) to prevent detailed stuffs from being printed. +* `compete` : logical. Set `TRUE` to print competitors rules thanks to competitors split. `FALSE` is default value. + +If `vt.tree` is a list, unique subgroups are printed. + +```{r} +# use tr.class computed previously +vt.sbgrps <- vt.subgroups(tr.class) +# print tables with knitr package +library(knitr) +knitr::kable(vt.sbgrps) +``` + +You can plot one tree with package `rpart.plot` + +```{r, echo=F, fig.align='center', fig.height=4, fig.width=6} +library(rpart.plot) +rpart.plot(tr.class$tree2$tree, type = 1, extra = 1) +``` + +If you want to see competitors split : + +```{r} +tr.class$tree2$createCompetitors() +head(tr.class$tree2$competitors) +``` + +If you want to print incidence of a subgroup : +```{r} +vt.o$getIncidences("PRAPACHE >= 26 & AGE >= 52") +# or +# tr.class$tree2$getIncidences("PRAPACHE >= 26 & AGE >= 52") +``` + +If you want to get infos about the tree + +```{r} +tr.class$tree2$getInfos() +# access Ahat +# tr.class$tree2$Ahat +``` + +You can re-run rpart computation: + +```{r} +tr.class$tree2$run(maxdepth = 2) +``` + +Type `?VT.tree` for details. + +----------- + +# Questions + +This vignette is a bit messy right now, therefore feel free to ask anything to the repository issue reports : + +1. https://github.com/prise6/aVirtualTwins +2. read documentation with `?aVirtualTwins` diff --git a/inst/doc/full-example.html b/inst/doc/full-example.html index 2290802..1d7ac96 100644 --- a/inst/doc/full-example.html +++ b/inst/doc/full-example.html @@ -10,7 +10,7 @@ - +
The goal of this vignette is to show most of all possibilies with aVT (for aVirtualTwins meaning adaptation of Virtual Twins method) package.
@@ -298,7 +311,7 @@ model.fold <- vt.forest(vt.object
: return of vt.data()
functiontwin1
: estimate of \(P(Y_{i} = 1 | T = T_{i})\) : meaning response probability under the correct treatment.twin1
: estimate of \(P(Y_{i} = 1 | T = 1-T_{i})\) : meaning response probability under the other treatment.twin2
: estimate of \(P(Y_{i} = 1 | T = 1-T_{i})\) : meaning response probability under the other treatment.method
: absolute (default), relative or logit. See ?VT.difft
for details.# you get twin1 and twin2 by your own method
@@ -342,7 +355,10 @@ model.difft$computeDifft()
tr.class <- vt.tree("class",
vt.difft = vt.f.rf,
sens = ">",
- threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1)))
+ threshold = quantile(vt.f.rf$difft, seq(.5, .8, .1)),
+ maxdepth = 3,
+ cp = 0,
+ maxcompete = 2)
# tr.class is a list if threshold is a vectoor
class(tr.class)
## [1] "list"
@@ -364,15 +380,187 @@ tr.reg <- vt.tree(# tr.class is a list if threshold is a vectoor
class(tr.reg)
## [1] "list"
-# acce trees with treeXX
+# access trees with treeXX
class(tr.reg$tree1)
## [1] "VT.tree.reg"
## attr(,"package")
## [1] "aVirtualTwins"
+
Once trees have been computed, you surely want to see what are the subgroups. This package provides a wrapper function of intern methods of VT.tree
class : vt.subgroups()
.
This function takes in argument :
+vt.tree
: object or list of class VT.tree
. Return of the vt.tree()
function.only.leaf
: logical. Set TRUE
(default) to visualize only terminal nodes.only.fav
: logical. Set TRUE
(default) to visualize only class 1 nodes. (\(\hat{A}\))tables
: logical. Set FALSE
(default) to prevent tables of incidences from being printed.verbose
: logical. Set FALSE
(default) to prevent detailed stuffs from being printed.compete
: logical. Set TRUE
to print competitors rules thanks to competitors split. FALSE
is default value.If vt.tree
is a list, unique subgroups are printed.
# use tr.class computed previously
+vt.sbgrps <- vt.subgroups(tr.class)
+# print tables with knitr package
+library(knitr)
+knitr::kable(vt.sbgrps)
++ | Subgroup | +Subgroup size | +Treatement event rate | +Control event rate | +Treatment sample size | +Control sample size | +RR (resub) | +RR (snd) | +
---|---|---|---|---|---|---|---|---|
tree1.11 | +PRAPACHE< 26.5 & AGE>=51.74 & BLGCS< 11.5 | +49 | +0.485 | +0.375 | +33 | +16 | +1.293 | +1.043 | +
tree1.3 | +PRAPACHE>=26.5 | +157 | +0.752 | +0.327 | +105 | +52 | +2.300 | +1.865 | +
tree2.11 | +PRAPACHE< 26.5 & BLGCS< 10.5 & AGE>=64.68 | +14 | +0.7 | +0.5 | +10 | +4 | +1.400 | +1.200 | +
tree2.13 | +PRAPACHE>=26.5 & AGE< 51.74 & BLLCREAT< 2.3 | +21 | +0.375 | +0.6 | +16 | +5 | +0.625 | +1.506 | +
tree2.7 | +PRAPACHE>=26.5 & AGE>=51.74 | +120 | +0.897 | +0.31 | +78 | +42 | +2.894 | +2.007 | +
tree3.13 | +PRAPACHE>=26.5 & AGE< 51.74 & BLLBILI>=2.95 | +13 | +0.333 | +0.25 | +9 | +4 | +1.332 | +1.564 | +
tree4 | +PRAPACHE>=26.5 & AGE>=51.74 & PRAPACHE>=28.5 | +89 | +0.915 | +0.333 | +59 | +30 | +2.748 | +2.087 | +
You can plot one tree with package rpart.plot
If you want to see competitors split :
+tr.class$tree2$createCompetitors()
+head(tr.class$tree2$competitors)
+## count ncat improve index var path string
+## 1 470 -1 119.987009 26.500 PRAPACHE 2 PRAPACHE < 26.5
+## 2 470 1 37.018261 10.500 BLGCS 2 BLGCS >= 10.5
+## 3 470 -1 30.491058 61.671 AGE 2 AGE < 61.671
+## 9 313 1 6.349646 10.500 BLGCS 4 BLGCS >= 10.5
+## 10 313 -1 5.075061 61.671 AGE 4 AGE < 61.671
+## 11 313 -1 2.027870 19.500 PRAPACHE 4 PRAPACHE < 19.5
+If you want to print incidence of a subgroup :
+vt.o$getIncidences("PRAPACHE >= 26 & AGE >= 52")
+## $table.selected
+## $table.selected$table
+## trt
+## resp 0 1 sum
+## 0 30 18 48
+## 1 15 72 87
+## sum 45 90 135
+## Incidence 0.333 0.8 0.644
+##
+## $table.selected$rr
+## [1] 2.402402
+##
+##
+## $table.not.selected
+## $table.not.selected$table
+## trt
+## resp 0 1 sum
+## 0 71 170 241
+## 1 37 57 94
+## sum 108 227 335
+## Incidence 0.343 0.251 0.281
+##
+## $table.not.selected$rr
+## [1] 0.7317784
+# or
+# tr.class$tree2$getIncidences("PRAPACHE >= 26 & AGE >= 52")
+If you want to get infos about the tree
+tr.class$tree2$getInfos()
+##
+## Threshold = 0.0675
+## Delta = 0.0671
+## Sens : >
+## Size of Ahat : 155
+# access Ahat
+# tr.class$tree2$Ahat
+You can re-run rpart computation:
+tr.class$tree2$run(maxdepth = 2)
+Type ?VT.tree
for details.
This vignette is a bit messy right now, therefore feel free to ask anything to the repository issue reports :
+?aVirtualTwins