knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

casebase

Coverage Status CRAN Downloads Lifecycle: maturing R-CMD-check Codecov test coverage

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 with:

install.packages("casebase")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("sahirbhatnagar/casebase")

Vignettes

See the package website for example usage of the functions. This includes

  1. Fitting Smooth Hazard Functions
  2. Competing Risks Analysis
  3. Population Time Plots
  4. Customizing Population Time Plots
  5. Plot Hazards and Hazard Ratios
  6. Plot Cumulative Incidence and Survival Curves

useR! 2019 Toulouse - Presentation

Jesse useR

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 (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)
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:

plot(popTime(eprchd, exposure = "treatment"))

Fit a Smooth Hazard Model

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)

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:

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:

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:

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:

Other packages with similar objectives but different parametric forms:

Citation

citation('casebase')

Contact

Latest news

You can see the most recent changes to the package in the NEWS file

Code of Conduct

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.



sahirbhatnagar/casebase documentation built on April 10, 2024, 6:01 a.m.