bootstrap() resamples the subjects with replacement, fits a Kaplan-Meier curve to each
resample, and reads a summary statistic from it. The spread of the statistic over the resamples
gives its standard error and a confidence interval. This is useful for quantities without a
simple closed-form interval, such as the difference in median survival between two groups.
Arguments
- formula
A formula with a
Surv()response on the left and either1or one or more grouping variables on the right, such asSurv(time, status) ~ sex. The response is right-censored or counting-process data.- data
A data frame holding the variables in
formula.- statistic
The quantity to bootstrap:
"median","quantile","rmst","survival","median_diff","rmst_diff", or"survival_diff", or a function that takes akaplan_meier()fit and returns one number. The"_diff"statistics need a formula with exactly two groups, and the others (apart from a function) need a formula without groups.- tau
The end of the window for
"rmst"and"rmst_diff".- p
The proportion of subjects who have had the event, between 0 and 1, for
"quantile".- times
The time of the survival probability for
"survival"and"survival_diff".- weights
Optional case weights, a column of
dataor a numeric vector. Each resampled subject keeps its weight.- subset
An optional expression selecting the rows of
datato use.- na.action
What to do with rows that have missing values. The default drops them.
- n_boot
The number of resamples. The default is
1000.- conf_level
The confidence level, between 0 and 1. The default is
0.95.- ci_type
The kind of interval:
"percentile"(the default),"normal", or"bca".
Value
A greenwood_bootstrap object with the estimate from the original data, its
bootstrap std_error, conf_low, conf_high, conf_level, ci_type, n_boot, the
statistic, the two groups compared by a "_diff" statistic, and the replicates
(distribution, with NA for any that failed). as.data.frame() gives the estimate, the
standard error, and the limits as a one-row data frame.
Details
The built-in statistics are the median survival time ("median"), the p quantile of survival
time ("quantile"), the restricted mean survival time up to tau ("rmst"), and the survival
probability at times ("survival"). Each of the median, RMST, and survival probability also
has a two-group form ("median_diff", "rmst_diff", and "survival_diff") that gives the
value in the first group minus the value in the second. The groups come from the right-hand side
of formula, in the order of the curves of kaplan_meier(), and the two-group forms resample
within each group so every resample keeps the group sizes. Any other summary can be given as a
function that takes a kaplan_meier() fit and returns one number.
A resample whose statistic can't be computed (an error, or a median that the curve never reaches) counts as missing and is left out of the standard error and the interval. The standard error is the standard deviation of the remaining replicates.
The "percentile" interval takes the \(\alpha / 2\) and \(1 - \alpha / 2\) quantiles of the
replicates, and the "normal" interval is the estimate plus or minus \(z\) standard errors.
The "bca" (bias-corrected and accelerated) interval shifts the percentiles by the bias
correction \(z_0 = \Phi^{-1}(\text{share of replicates below the estimate})\) and the
acceleration \(a = \sum d_i^3 / (6 (\sum d_i^2)^{3/2})\), where \(d_i\) are the differences
between the mean of the leave-one-out (jackknife) values and each of them. The acceleration is 0
when a jackknife value is missing. The jackknife refits the curve once per subject.
Resampling draws from R's random number generator, so call set.seed() first for results that
can be repeated.
References
Efron, B., and Tibshirani, R. J. (1993). An Introduction to the Bootstrap. Chapman and Hall.
Examples
lung <- data.frame(
time = c(306, 455, 1010, 210, 883, 1022, 310, 361, 218, 166, 170, 654, 728, 71, 567),
status = c(2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2),
sex = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2)
)
set.seed(1)
bootstrap(Surv(time, status) ~ 1, data = lung, statistic = "median", n_boot = 200)
#> <bootstrap> Surv(time, status) ~ 1
#> Statistic: median, 200 resamples, percentile interval
#>
#> estimate std_error 0.95 LCL 0.95 UCL
#> 361 120.1161 210 654
# The difference in restricted mean survival time between the sexes
bootstrap(Surv(time, status) ~ sex,
data = lung, statistic = "rmst_diff", tau = 365, n_boot = 200
)
#> <bootstrap> Surv(time, status) ~ sex
#> Statistic: rmst_diff (sex=1 minus sex=2), 200 resamples, percentile interval
#>
#> estimate std_error 0.95 LCL 0.95 UCL
#> 66.44643 42.21345 -15.775 141.4134
# Any summary of the curve, here the survival probability halfway through a year
half_year <- function(fit) predict(fit, times = 182.5)$estimate
bootstrap(Surv(time, status) ~ 1,
data = lung, statistic = half_year, n_boot = 200, ci_type = "bca"
)
#> <bootstrap> Surv(time, status) ~ 1
#> Statistic: custom, 200 resamples, bca interval
#>
#> estimate std_error 0.95 LCL 0.95 UCL
#> 0.8 0.09856083 0.5333333 0.9333333