Restricted Mean Survival Time from Cox Models

Calculates restricted mean survival time from predicted Cox proportional hazards survival curves using composite Simpson's rule and provides plots with shaded areas under the survival curves. Includes simulated survival data for reproducible examples.


CoxRMSTSimpson

Overview

CoxRMSTSimpson calculates restricted mean survival time (RMST) from predicted Cox proportional hazards survival curves using composite Simpson's 1/3 numerical integration.

The package provides:

  • RMST estimation up to a specified restriction time.
  • Comparisons across user-defined covariate profiles.
  • Plots with shaded areas under predicted survival curves.
  • Simulation of survival data for reproducible examples.

The package combines established statistical and numerical methods in a reusable R workflow. It does not claim that RMST or Simpson's rule is a new statistical method.

Installation

Install the development version from GitHub:

install.packages("remotes")

remotes::install_github("fordeia/CoxRMSTSimpson")

This installation command assumes that the repository is publicly available on GitHub under the username fordeia.

Example

library(CoxRMSTSimpson)
library(survival)

# Simulate data
df <- simulate_survival_data(
  n = 200,
  beta = 0.7,
  lambda = 0.03,
  censor_rate = 0.005,
  seed = 123
)

# Fit Cox proportional hazards model
fit <- coxph(
  Surv(time, status) ~ X,
  data = df,
  ties = "breslow"
)

# Define profiles for X = 0 and X = 1
profiles <- data.frame(X = c(0, 1))
rownames(profiles) <- c("X = 0", "X = 1")

# Calculate RMST up to tau = 30
result <- cox_rmst(
  fit = fit,
  newdata = profiles,
  tau = 30,
  n_grid = 101
)

# Display estimates
print(result)

# Plot survival curves and shaded RMST areas
plot_cox_rmst(result, colors = c("blue", "red"))

Mathematical Definition

For a predicted survival curve $S(t)$, the restricted mean survival time up to a restriction time $\tau$ is defined as

$$ \operatorname{RMST}(\tau) = \int_0^\tau S(t),dt. $$

This package approximates the integral using composite Simpson's 1/3 rule on an equally spaced time grid with an odd number of grid points.

Limitations

The quality of the numerical approximation depends on the time grid and the predicted survival curve. Extending a survival estimate beyond supported follow-up does not provide new information. Select the restriction time based on the study design and available follow-up.

The reported RMST estimates do not automatically include standard errors or confidence intervals.

License

MIT

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("CoxRMSTSimpson")

0.1.0 by Ian Forde, 7 hours ago


Browse source code at https://github.com/cran/CoxRMSTSimpson


Authors: Ian Forde [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports survival, graphics, grDevices, stats

Suggests testthat


See at CRAN