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 calculates restricted mean survival time (RMST) from predicted Cox proportional hazards survival curves using composite Simpson's 1/3 numerical integration.
The package provides:
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.
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.
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"))
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.
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.
MIT