| Title: | Restricted Mean Survival Time from Cox Models |
|---|---|
| Description: | 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. |
| Authors: | Ian Forde [aut, cre] |
| Maintainer: | Ian Forde <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-22 19:26:36 UTC |
| Source: | https://github.com/cran/CoxRMSTSimpson |
Predicts survival curves for supplied covariate profiles and calculates their RMST using Simpson's rule.
cox_rmst(fit, newdata, tau, n_grid = 101)cox_rmst(fit, newdata, tau, n_grid = 101)
fit |
A fitted survival::coxph model. |
newdata |
Data frame of covariate profiles. Each row defines one survival curve. |
tau |
Positive restriction time. |
n_grid |
Odd number of equally spaced grid points. |
An object of class "cox_rmst" containing survival curves, RMST estimates, the fitted model, and the time grid.
library(survival) data(lung, package = "survival") fit <- coxph(Surv(time, status == 2) ~ age + sex, data = lung) profiles <- data.frame( age = c(50, 70), sex = c(1, 2), row.names = c("Younger", "Older") ) result <- cox_rmst(fit, newdata = profiles, tau = 365) print(result)library(survival) data(lung, package = "survival") fit <- coxph(Surv(time, status == 2) ~ age + sex, data = lung) profiles <- data.frame( age = c(50, 70), sex = c(1, 2), row.names = c("Younger", "Older") ) result <- cox_rmst(fit, newdata = profiles, tau = 365) print(result)
Plot Cox Survival Curves with Shaded RMST Areas
plot_cox_rmst(x, colors = NULL, alpha = 0.2, legend_position = "topright", ...)plot_cox_rmst(x, colors = NULL, alpha = 0.2, legend_position = "topright", ...)
x |
An object returned by cox_rmst(). |
colors |
Colors for the survival curves. |
alpha |
Transparency for shaded areas, between 0 and 1. |
legend_position |
Position passed to graphics::legend(). |
... |
Additional arguments reserved for future methods. |
Invisibly returns x.
library(survival) data(lung, package = "survival") fit <- coxph(Surv(time, status == 2) ~ age + sex, data = lung) profiles <- data.frame( age = c(50, 70), sex = c(1, 2), row.names = c("Younger", "Older") ) result <- cox_rmst(fit, newdata = profiles, tau = 365) plot_cox_rmst(result)library(survival) data(lung, package = "survival") fit <- coxph(Surv(time, status == 2) ~ age + sex, data = lung) profiles <- data.frame( age = c(50, 70), sex = c(1, 2), row.names = c("Younger", "Older") ) result <- cox_rmst(fit, newdata = profiles, tau = 365) plot_cox_rmst(result)
Calculates the area under a survival curve using composite Simpson's 1/3 rule.
simpson_rmst(t, S)simpson_rmst(t, S)
t |
Equally spaced, increasing time points. |
S |
Survival probabilities corresponding to t. |
A numeric scalar representing the integrated area.
Simulate Survival Data Under a Proportional Hazards Model
simulate_survival_data( n = 200, beta = 0.7, lambda = 0.03, censor_rate = 0.005, seed = NULL )simulate_survival_data( n = 200, beta = 0.7, lambda = 0.03, censor_rate = 0.005, seed = NULL )
n |
Number of subjects. |
beta |
True regression coefficient for X. |
lambda |
Baseline exponential hazard rate. |
censor_rate |
Independent exponential censoring rate. |
seed |
Optional random seed. |
A data frame with time, status, and X.