| Title: | Time-Varying Restricted Mean Survival Time from Survival Matrices |
|---|---|
| Description: | Utilities for restricted mean survival time (RMST) and time-varying restricted mean survival time quantities computed from survival curves provided on a time grid. The package is model-agnostic and accepts only a time vector and survival matrices, returning RMST-based quantities and bootstrap summaries. For restricted mean survival time methodology, see Royston and Parmar (2013) <doi:10.1186/1471-2288-13-152>. |
| Authors: | Imad EL BADISY [aut, cre] |
| Maintainer: | Imad EL BADISY <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.6 |
| Built: | 2026-05-18 09:58:47 UTC |
| Source: | https://github.com/ielbadisy/tvrmst |
Construct a survival matrix object
as_survmat(S, time, id = NULL, group = NULL)as_survmat(S, time, id = NULL, group = NULL)
S |
Numeric matrix of survival probabilities (rows = subjects, columns = time). |
time |
Numeric strictly increasing time grid with |
id |
Optional subject identifiers. Defaults to |
group |
Optional group labels with length |
An object of class "survmat".
time <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time, group = c("A", "B")) xtime <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time, group = c("A", "B")) x
Coerce survival predictions to a numeric matrix
as_survprob_matrix(pred, times = NULL)as_survprob_matrix(pred, times = NULL)
pred |
Prediction output from a model. |
times |
Unused placeholder for API compatibility. |
Numeric matrix with rows as subjects and columns as times.
pred <- data.frame( t0 = c(1.0, 1.0), t1 = c(0.8, 0.7), t2 = c(0.6, 0.5) ) as_survprob_matrix(pred)pred <- data.frame( t0 = c(1.0, 1.0), t1 = c(0.8, 0.7), t2 = c(0.6, 0.5) ) as_survprob_matrix(pred)
Row-bind survmat objects on a common time grid
bind_survmat(...)bind_survmat(...)
... |
One or more |
A combined survmat.
time <- c(0, 1, 2) xA <- as_survmat(matrix(c(1.0, 0.9, 0.7), nrow = 1), time, group = "A") xB <- as_survmat(matrix(c(1.0, 0.8, 0.6), nrow = 1), time, group = "B") x <- bind_survmat(xA, xB) nobs_survmat(x)time <- c(0, 1, 2) xA <- as_survmat(matrix(c(1.0, 0.9, 0.7), nrow = 1), time, group = "A") xB <- as_survmat(matrix(c(1.0, 0.8, 0.6), nrow = 1), time, group = "B") x <- bind_survmat(xA, xB) nobs_survmat(x)
Bootstrap CI for dynamic RMST delta curve
boot_rmst_delta(xA, xB, R = 300, conf = 0.95, seed = NULL)boot_rmst_delta(xA, xB, R = 300, conf = 0.95, seed = NULL)
xA |
A |
xB |
A |
R |
Number of bootstrap replicates. |
conf |
Confidence level in |
seed |
Optional RNG seed. |
A list with point estimate and percentile confidence bands.
time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) boot <- boot_rmst_delta(xA, xB, R = 10, seed = 1) boot$estimatetime <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) boot <- boot_rmst_delta(xA, xB, R = 10, seed = 1) boot$estimate
Generic bootstrap for curve-valued estimators
bootstrap_curve(est_fun, R = 300, conf = 0.95, seed = NULL, keep_reps = FALSE)bootstrap_curve(est_fun, R = 300, conf = 0.95, seed = NULL, keep_reps = FALSE)
est_fun |
Function of one argument |
R |
Number of replicates. |
conf |
Confidence level in |
seed |
Optional RNG seed. |
keep_reps |
If |
A list with estimate, lo, hi, and conf.
vals <- c(1, 2, 4, 8) boot <- bootstrap_curve( function(r) { if (is.null(r)) { mean(vals) } else { mean(sample(vals, replace = TRUE)) } }, R = 20, seed = 1 ) boot$estimatevals <- c(1, 2, 4, 8) boot <- bootstrap_curve( function(r) { if (is.null(r)) { mean(vals) } else { mean(sample(vals, replace = TRUE)) } }, R = 20, seed = 1 ) boot$estimate
Number of rows in a survmat
nobs_survmat(x)nobs_survmat(x)
x |
A |
Number of subjects.
time <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time) nobs_survmat(x)time <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time) nobs_survmat(x)
Plot bootstrap estimate with confidence ribbon
plot_boot_curve( boot, grid = NULL, title = "Bootstrap curve", xlab = "t", ylab = "estimate", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )plot_boot_curve( boot, grid = NULL, title = "Bootstrap curve", xlab = "t", ylab = "estimate", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )
boot |
List returned by |
grid |
Optional x-axis grid. If omitted, uses |
title |
Plot title. |
xlab |
X-axis label. |
ylab |
Y-axis label. |
x_scale |
Positive divisor applied to the x-axis values before plotting. |
y_scale |
Positive divisor applied to the y-axis values before plotting. |
x_unit |
Optional unit label appended to the x-axis title. |
y_unit |
Optional unit label appended to the y-axis title. |
A ggplot object.
time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) boot <- boot_rmst_delta(xA, xB, R = 10, seed = 1) plot_boot_curve(boot)time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) boot <- boot_rmst_delta(xA, xB, R = 10, seed = 1) plot_boot_curve(boot)
Plot a delta curve
plot_delta_curve( grid, delta, title = "Delta curve", xlab = "t", ylab = "Delta", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )plot_delta_curve( grid, delta, title = "Delta curve", xlab = "t", ylab = "Delta", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )
grid |
X-axis grid. |
delta |
Y values. |
title |
Plot title. |
xlab |
X-axis label. |
ylab |
Y-axis label. |
x_scale |
Positive divisor applied to the x-axis values before plotting. |
y_scale |
Positive divisor applied to the y-axis values before plotting. |
x_unit |
Optional unit label appended to the x-axis title. |
y_unit |
Optional unit label appended to the y-axis title. |
A ggplot object.
time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) d <- rmst_delta(xA, xB) plot_delta_curve(d$time, d$delta)time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) d <- rmst_delta(xA, xB) plot_delta_curve(d$time, d$delta)
Plot individual dynamic RMST curves by group
plot_rmst_individual_by_group( res, group, n_show_per_group = 30, title = "Individual dynamic RMST by group", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )plot_rmst_individual_by_group( res, group, n_show_per_group = 30, title = "Individual dynamic RMST by group", x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )
res |
Result from |
group |
Group vector aligned with rows of |
n_show_per_group |
Maximum number of individual curves shown per group. |
title |
Plot title. |
x_scale |
Positive divisor applied to the x-axis values before plotting. |
y_scale |
Positive divisor applied to the y-axis values before plotting. |
x_unit |
Optional unit label appended to the x-axis title. |
y_unit |
Optional unit label appended to the y-axis title. |
A ggplot object.
time <- c(0, 1, 2) S <- rbind( c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6), c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7) ) grp <- c("A", "A", "B", "B") x <- as_survmat(S, time, group = grp) res <- rmst_dynamic(x) plot_rmst_individual_by_group(res, grp, n_show_per_group = 2)time <- c(0, 1, 2) S <- rbind( c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6), c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7) ) grp <- c("A", "A", "B", "B") x <- as_survmat(S, time, group = grp) res <- rmst_dynamic(x) plot_rmst_individual_by_group(res, grp, n_show_per_group = 2)
Plot mean RMST curves for two arms
plot_rmst_two_arms( xA, xB, labels = c("Arm A", "Arm B"), title = NULL, xlab = "Time (tau)", ylab = "RMST(tau)", curve_colors = c("#1B6CA8", "#D95F02"), x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )plot_rmst_two_arms( xA, xB, labels = c("Arm A", "Arm B"), title = NULL, xlab = "Time (tau)", ylab = "RMST(tau)", curve_colors = c("#1B6CA8", "#D95F02"), x_scale = 1, y_scale = 1, x_unit = NULL, y_unit = NULL )
xA |
A |
xB |
A |
labels |
Two legend labels. |
title |
Plot title. Use |
xlab |
X-axis label. |
ylab |
Y-axis label. |
curve_colors |
Colors for the two curves. |
x_scale |
Positive divisor applied to the x-axis values before plotting. |
y_scale |
Positive divisor applied to the y-axis values before plotting. |
x_unit |
Optional unit label appended to the x-axis title. |
y_unit |
Optional unit label appended to the y-axis title. |
A ggplot object.
time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) plot_rmst_two_arms(xA, xB, labels = c("Control", "Treatment"))time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) plot_rmst_two_arms(xA, xB, labels = c("Control", "Treatment"))
Computes Delta(tau) = RMST_B(tau) - RMST_A(tau).
rmst_delta(xA, xB, tau = NULL)rmst_delta(xA, xB, tau = NULL)
xA |
A |
xB |
A |
tau |
Optional numeric horizons for interpolation. |
A list with RMST curves for both arms and the delta curve.
time <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) rmst_delta(xA, xB, tau = 1.5)$at_tautime <- c(0, 1, 2) xA <- as_survmat(rbind(c(1.0, 0.9, 0.7), c(1.0, 0.8, 0.6)), time, group = c("A", "A")) xB <- as_survmat(rbind(c(1.0, 0.95, 0.8), c(1.0, 0.85, 0.7)), time, group = c("B", "B")) rmst_delta(xA, xB, tau = 1.5)$at_tau
Computes RMST_i(tau) = integral_0^tau S_i(u) du over the provided grid.
rmst_dynamic(x, tau = NULL, by = x$group)rmst_dynamic(x, tau = NULL, by = x$group)
x |
A |
tau |
Optional numeric horizons for interpolation. |
by |
Optional grouping variable. Defaults to |
A list with individual and mean RMST curves.
time <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time, group = c("A", "A")) res <- rmst_dynamic(x, tau = c(0.5, 1.5)) res$mean res$at_tautime <- c(0, 1, 2) S <- rbind( c(1.0, 0.8, 0.6), c(1.0, 0.7, 0.5) ) x <- as_survmat(S, time, group = c("A", "A")) res <- rmst_dynamic(x, tau = c(0.5, 1.5)) res$mean res$at_tau
Tools for dynamic restricted mean survival time estimation, restricted mean survival time contrasts, bootstrap uncertainty, and plotting from survival probability matrices evaluated on a common time grid.