| Title: | Restricted Mean Survival Time from Cox Models |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0) |
| Imports: | survival, graphics, grDevices, stats |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-14 08:45:43 UTC; fordeia |
| Author: | Ian Forde [aut, cre] |
| Maintainer: | Ian Forde <fordeia@appstate.edu> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-22 16:20:14 UTC |
Calculate RMST from a Cox Model
Description
Predicts survival curves for supplied covariate profiles and calculates their RMST using Simpson's rule.
Usage
cox_rmst(fit, newdata, tau, n_grid = 101)
Arguments
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. |
Value
An object of class "cox_rmst" containing survival curves, RMST estimates, the fitted model, and the time grid.
Examples
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
Description
Plot Cox Survival Curves with Shaded RMST Areas
Usage
plot_cox_rmst(x, colors = NULL, alpha = 0.2, legend_position = "topright", ...)
Arguments
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. |
Value
Invisibly returns x.
Examples
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)
Integrate a Survival Curve Using Simpson's Rule
Description
Calculates the area under a survival curve using composite Simpson's 1/3 rule.
Usage
simpson_rmst(t, S)
Arguments
t |
Equally spaced, increasing time points. |
S |
Survival probabilities corresponding to t. |
Value
A numeric scalar representing the integrated area.
Simulate Survival Data Under a Proportional Hazards Model
Description
Simulate Survival Data Under a Proportional Hazards Model
Usage
simulate_survival_data(
n = 200,
beta = 0.7,
lambda = 0.03,
censor_rate = 0.005,
seed = NULL
)
Arguments
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. |
Value
A data frame with time, status, and X.