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 @@ - + Virtual Twins Examples @@ -54,10 +54,23 @@ code > span.er { color: #ff0000; font-weight: bold; } +
+

Contents

+
    +
  1. Introduction
  2. +
  3. Quick preview
  4. +
  5. Sepsis dataset
  6. +
  7. Create object virtual twins
  8. +
  9. Step 1 : compute probabilities
  10. +
  11. Step 2 : Estimate a decision tree
  12. +
  13. Subgroups and results
  14. +
  15. Questions
  16. +
+

Introduction

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() 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.
  • # 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"
    +
    -
    -

    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 :

    + +

    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)
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    SubgroupSubgroup sizeTreatement event rateControl event rateTreatment sample sizeControl sample sizeRR (resub)RR (snd)
    tree1.11PRAPACHE< 26.5 & AGE>=51.74 & BLGCS< 11.5490.4850.37533161.2931.043
    tree1.3PRAPACHE>=26.51570.7520.327105522.3001.865
    tree2.11PRAPACHE< 26.5 & BLGCS< 10.5 & AGE>=64.68140.70.51041.4001.200
    tree2.13PRAPACHE>=26.5 & AGE< 51.74 & BLLCREAT< 2.3210.3750.61650.6251.506
    tree2.7PRAPACHE>=26.5 & AGE>=51.741200.8970.3178422.8942.007
    tree3.13PRAPACHE>=26.5 & AGE< 51.74 & BLLBILI>=2.95130.3330.25941.3321.564
    tree4PRAPACHE>=26.5 & AGE>=51.74 & PRAPACHE>=28.5890.9150.33359302.7482.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.

    +
    +
    +
    +

    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. +
    3. read documentation with ?aVirtualTwins
    4. +
    diff --git a/man/vt.subgroups.Rd b/man/vt.subgroups.Rd index 1ba1525..9872287 100644 --- a/man/vt.subgroups.Rd +++ b/man/vt.subgroups.Rd @@ -20,6 +20,9 @@ favorable label of the tree). TRUE is default.} default.} \item{verbose}{print infos during computation. FALSE is default.} + +\item{compete}{print competitors rules thanks to competitors computation of + the tree} } \value{ data.frame of rules