-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
198 lines (130 loc) · 7.62 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
---
output: github_document
editor_options:
chunk_output_type: inline
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# casebase
<!-- badges: start -->
[![Coverage Status](https://img.shields.io/codecov/c/github/sahirbhatnagar/casebase/master.svg)](https://app.codecov.io/github/sahirbhatnagar/casebase?branch=master) [![CRAN](https://www.r-pkg.org/badges/version/casebase?color=blue)](https://cran.r-project.org/package=casebase) [![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/casebase?color=green)](https://www.r-pkg.org/pkg/casebase)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![R-CMD-check](https://github.com/sahirbhatnagar/casebase/workflows/R-CMD-check/badge.svg)](https://github.com/sahirbhatnagar/casebase/actions)
[![Codecov test coverage](https://codecov.io/gh/sahirbhatnagar/casebase/branch/master/graph/badge.svg)](https://app.codecov.io/gh/sahirbhatnagar/casebase?branch=master)
<!-- badges: end -->
`casebase` is an R package for fitting flexible and fully parametric hazard regression models to survival data with single event type or multiple competing causes via logistic and multinomial regression. Our formulation allows for arbitrary functional forms of time and its interactions with other predictors for time-dependent hazards and hazard ratios. From the fitted hazard model, we provide functions to readily calculate and plot cumulative incidence and survival curves for a given covariate profile. This approach accommodates any log-linear hazard function of prognostic time, treatment, and covariates, and readily allows for non-proportionality. We also provide a plot method for visualizing incidence density via population time plots.
## Installation
You can install the released version of casebase from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("casebase")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("sahirbhatnagar/casebase")
```
## Vignettes
See the [package website](http://sahirbhatnagar.com/casebase/) for example usage of the functions. This includes
1. [Fitting Smooth Hazard Functions](http://sahirbhatnagar.com/casebase/articles/smoothHazard.html)
2. [Competing Risks Analysis](http://sahirbhatnagar.com/casebase/articles/competingRisk.html)
3. [Population Time Plots](http://sahirbhatnagar.com/casebase/articles/popTime.html)
4. [Customizing Population Time Plots](http://sahirbhatnagar.com/casebase/articles/customizingpopTime.html)
5. [Plot Hazards and Hazard Ratios](http://sahirbhatnagar.com/casebase/articles/plotsmoothHazard.html)
6. [Plot Cumulative Incidence and Survival Curves](http://sahirbhatnagar.com/casebase/articles/plotabsRisk.html)
## useR! 2019 Toulouse - Presentation
[![Jesse useR](man/figures/jesse-user.png)](https://www.youtube.com/watch?v=DlppjRYVklQ)
## Quickstart
This is a basic example which shows you some of the main functionalities of the `casebase` package. We use data from the estrogen plus progestin trial from the [Women's Health Initiative](https://www.nejm.org/doi/full/10.1056/NEJMoa030808) (included in the `casebase` package). This randomized clinical trial investigated the effect of estrogen plus progestin (`estPro`) on coronary heart disease (CHD) risk in 16,608 postmenopausal women who were 50 to 79 years of age at base line. Participants were randomly assigned to receive `estPro` or `placebo`. The primary efficacy outcome of the trial was CHD (nonfatal myocardial infarction or death due to CHD).
```{r example}
library(casebase)
library(visreg)
library(splines)
data("eprchd")
```
### Population Time Plots
We first visualize the data with a population time plot. For each treatment arm, we plot the observed person time in gray, and the case series as colored dots. It gives us a good visual representation of the incidence density:
```{r, message=FALSE}
plot(popTime(eprchd, exposure = "treatment"))
```
### Fit a Smooth Hazard Model
We model the hazard as a function of time, treatment arm and their interaction:
```{r eprchd, results='show'}
eprchd <- transform(eprchd,
treatment = factor(treatment, levels = c("placebo","estPro")))
fit <- fitSmoothHazard(status ~ treatment*ns(time, df = 3),
data = eprchd,
time = "time")
summary(fit)
```
Since the output object from ```fitSmoothHazard``` inherits from the ```glm``` class, we see a familiar result when using the function ```summary```.
### Time-Dependent Hazard Function
The treatment effect on the hazard is somewhat difficult to interpret because of its interaction with the spline term on time. In these situations, it is often more instructive to visualize the relationship. For example, we can easily plot the hazard function for each treatment arm:
```{r, results='show', R.options=list(max.print=1)}
plot(fit, hazard.params = list(xvar = "time", by = "treatment"))
```
### Time-Dependent Hazard Ratio
We can also plot the time-dependent hazard ratio and 95% confidence band:
```{r plot-mason, results='show'}
newtime <- quantile(eprchd$time,
probs = seq(0.01, 0.99, 0.01))
# reference category
newdata <- data.frame(treatment = factor("placebo",
levels = c("placebo", "estPro")),
time = newtime)
plot(fit,
type = "hr",
newdata = newdata,
var = "treatment",
increment = 1,
xvar = "time",
ci = T,
rug = T)
```
### Cumulative Incidence Function (CIF)
We can also calculate and plot the cumulative incidence function:
```{r}
smooth_risk <- absoluteRisk(object = fit,
newdata = data.frame(treatment = c("placebo", "estPro")))
plot(smooth_risk, id.names = c("placebo", "estPro"))
```
## Class structure
The `casebase` package uses the following hierarchy of classes for the output of `fitSmoothHazard`:
```
casebase:
singleEventCB:
- glm
- gam
- cv.glmnet
CompRisk:
- vglm
```
The class `singleEventCB` is an `S3` class, and we also keep track of the classes appearing below. The class `CompRisk` is an `S4` class that inherits from `vglm`.
## Credit
This package is makes use of several existing packages including:
* [`VGAM`](https://cran.r-project.org/package=VGAM) for fitting multinomial logistic regression models
* [`survival`](https://cran.r-project.org/package=survival) for survival models
* [`ggplot2`](https://cran.r-project.org/package=ggplot2) for plotting the population time plots
* [`data.table`](https://cran.r-project.org/package=data.table) for efficient handling of large datasets
Other packages with similar objectives but different parametric forms:
* [`rstpm2`](https://cran.r-project.org/package=rstpm2)
* [`flexsurv`](https://cran.r-project.org/package=flexsurv)
* [`SmoothHazard`](https://cran.r-project.org/package=SmoothHazard)
## Citation
```{r}
citation('casebase')
```
## Contact
* Issues: <https://github.com/sahirbhatnagar/casebase/issues>
* Pull Requests: <https://github.com/sahirbhatnagar/casebase/>
* e-mail: <sahir.bhatnagar@gmail.com>, <max.turgeon@umanitoba.ca>
## Latest news
You can see the most recent changes to the package in the [NEWS file](https://sahirbhatnagar.com/casebase/news/)
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](https://sahirbhatnagar.com/casebase/CONDUCT.html). By participating in this project you agree to abide by its terms.