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.
You can install the released version of casebase from CRAN with:
install.packages("casebase")
And the development version from GitHub with:
# install.packages("devtools")
devtools::install_github("sahirbhatnagar/casebase")
See the package website for example usage of the functions. This includes
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 (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).
library(casebase)
#> See example usage at http://sahirbhatnagar.com/casebase/
library(visreg)
library(splines)
data("eprchd")
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:
We model the hazard as a function of time, treatment arm and their interaction:
eprchd <- transform(eprchd,
treatment = factor(treatment, levels = c("placebo","estPro")))
fit <- fitSmoothHazard(status ~ treatment*ns(time, df = 3),
data = eprchd,
time = "time")
summary(fit)
#> Fitting smooth hazards with case-base sampling
#>
#> Sample size: 16608
#> Number of events: 324
#> Number of base moments: 32400
#> ----
#>
#> Call:
#> fitSmoothHazard(formula = status ~ treatment * ns(time, df = 3),
#> data = eprchd, time = "time")
#>
#> Deviance Residuals:
#> Min 1Q Median 3Q Max
#> -0.2344 -0.1483 -0.1380 -0.1267 3.1466
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -5.80408 0.30090 -19.289 < 2e-16 ***
#> treatmentestPro 0.59882 0.37743 1.587 0.112608
#> ns(time, df = 3)1 -0.36224 0.35878 -1.010 0.312654
#> ns(time, df = 3)2 0.58913 0.73465 0.802 0.422601
#> ns(time, df = 3)3 1.26391 0.34033 3.714 0.000204 ***
#> treatmentestPro:ns(time, df = 3)1 0.05593 0.48546 0.115 0.908274
#> treatmentestPro:ns(time, df = 3)2 -1.19576 0.94034 -1.272 0.203506
#> treatmentestPro:ns(time, df = 3)3 -0.97627 0.48228 -2.024 0.042942 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 3635.4 on 32723 degrees of freedom
#> Residual deviance: 3615.2 on 32716 degrees of freedom
#> AIC: 3631.2
#>
#> Number of Fisher Scoring iterations: 7
Since the output object from fitSmoothHazard
inherits from the glm
class, we see a familiar result when using the function summary
.
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:
We can also plot the time-dependent hazard ratio and 95% confidence band:
We can also calculate and plot the cumulative incidence function:
smooth_risk <- absoluteRisk(object = fit,
newdata = data.frame(treatment = c("placebo", "estPro")))
plot(smooth_risk, id.names = c("placebo", "estPro"))
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
.
This package is makes use of several existing packages including:
VGAM
for fitting multinomial logistic regression modelssurvival
for survival modelsggplot2
for plotting the population time plotsdata.table
for efficient handling of large datasetsOther packages with similar objectives but different parametric forms:
citation('casebase')
#>
#> To cite casebase in publications use:
#>
#> Bhatnagar S, Turgeon M, Islam J, Saarela O, Hanley J (2020).
#> _casebase: Fitting Flexible Smooth-in-Time Hazards and Risk Functions
#> via Logistic and Multinomial Regression_. R package version 0.9.0,
#> <https://CRAN.R-project.org/package=casebase>.
#>
#> Hanley, James A., and Olli S. Miettinen. Fitting smooth-in-time
#> prognostic risk functions via logistic regression. International
#> Journal of Biostatistics 5.1 (2009): 1125-1125.
#>
#> Saarela, Olli. A case-base sampling method for estimating recurrent
#> event intensities. Lifetime data analysis 22.4 (2016): 589-605.
#>
#> If competing risks analyis is used, please also cite
#>
#> Saarela, Olli, and Elja Arjas. Non-parametric Bayesian Hazard
#> Regression for Chronic Disease Risk Assessment. Scandinavian Journal
#> of Statistics 42.2 (2015): 609-626.
#>
#> To see these entries in BibTeX format, use 'print(<citation>,
#> bibtex=TRUE)', 'toBibtex(.)', or set
#> 'options(citation.bibtex.max=999)'.
You can see the most recent changes to the package in the NEWS file
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.