FastSurvival provides fast alternatives to the standard survival analysis functions in the survival package, together with a simulation layer for designing and evaluating time-to-event trials. Every function is designed for repeated evaluation inside large simulation loops, where the iterative or object-building overhead of the standard implementations becomes a bottleneck. Core computations are implemented in C++ via Rcpp.
The package has two families of functions. Collett (2023) gives the methodological background of the standard methods they implement.
The estimation and testing functions operate on a single dataset and
return an S3 object with a print() method.
survfit_fast() evaluates the Kaplan-Meier estimate at a
single time point. survdiff_fast() computes the log-rank
test and its weighted and stratified variants. coxph_fast()
fits the Cox proportional hazards model for two groups.
rmst_fast() returns the restricted mean survival time, and
wmst_fast() the window mean survival time over an interval.
milestone_fast() compares survival at a milestone
timepoint, and medsurv_fast() compares median survival
times. maxcombo_fast() computes the max-combo test,
rmw_fast() the robust modestly-weighted log-rank test, and
wkm_fast() the weighted Kaplan-Meier (Pepe-Fleming) test.
ahsw_fast() computes the average hazard with survival
weight, and ahr_fast() the Kalbfleisch-Prentice average
hazard ratio.
The simulation functions support a full simulation study.
simdata_fast() generates individual patient data for
one-group, two-group, or multi-arm trials. cutoff_fast()
determines the calendar time of every analysis look in every simulated
trial from combined event and calendar-time rules.
analysis_fast() performs interim or sequential analyses of
the simulated data at one or more looks, and can compute any of the
estimation and testing statistics above, optionally within subgroups.
switch_fast() applies treatment switching to the simulated
data, at progression or after an interim analysis.
pairwise_fast() compares each experimental arm of a
multi-arm trial with a shared control. simsummary_fast()
aggregates the operating characteristics from the analysis output
against supplied boundaries.
The following example uses the ovarian dataset from the
survival package, with a one-sided test of treatment benefit
(side = 1).
library(survival)
# Single-time-point Kaplan-Meier estimate
ord <- order(ovarian$futime)
survfit_fast(ovarian$futime[ord], ovarian$fustat[ord],
t_eval = 500, conf.type = "log")
#> Kaplan-Meier survival estimate (single time point)
#>
#> survival std.err lower 95% upper 95%
#> t = 500 0.5961 0.0999 0.4291 0.8279
#>
#> Confidence interval type: log
# Log-rank test
survdiff_fast(ovarian$futime, ovarian$fustat, ovarian$rx,
control = 1, side = 1)
#> Log-rank test (two-group)
#>
#> N = 26, control = 1
#>
#> Observed Expected (O-E)^2/E (O-E)^2/V
#> control 7 5.2335 0.5962 1.0627
#> treatment 5 6.7665 0.4612 1.0627
#>
#> Z = -1.031, one-sided p-value = 0.1513
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Hazard ratio from the Cox model
coxph_fast(ovarian$futime, ovarian$fustat, ovarian$rx,
control = 1, side = 1)
#> Cox proportional hazards model for two groups
#>
#> control = 1
#> ties = efron
#> alternative = one.sided
#>
#> Coefficients:
#> coef exp(coef) se(coef) z Pr(<z)
#> group -0.5964 0.5508 0.5870 -1.016 0.155
#>
#> Hazard ratio and 95% Wald confidence interval:
#> exp(coef) exp(-coef) lower .95 upper .95
#> group 0.5508 1.8155 0.1743 1.7404For the analysis of a single data set the functions also accept a
model formula with a data frame, as the functions of the survival
package do. The control group is then the first level of the group
variable, unless control is given. Inside simulation loops
the vector interface remains the faster choice. Every result has an
as.data.frame() method that returns its estimates and tests
with the same columns, and coef() and
confint() methods for the estimates; ratios are reported on
the log scale.
fit <- coxph_fast(Surv(futime, fustat) ~ rx, data = ovarian, side = 1)
as.data.frame(fit)
#> term estimate std.error conf.low conf.high statistic p.value
#> 1 coef -0.59638 0.5869895 -1.746858 0.5540983 -1.015998 0.1548152
exp(confint(fit))
#> 2.5 % 97.5 %
#> coef 0.1743207 1.740371
rmst_fast(Surv(futime, fustat) ~ rx, data = ovarian, tau = 500) |>
as.data.frame()
#> term estimate std.error conf.low conf.high statistic
#> 1 rmst.ctrl 373.6923077 44.9503848 285.59117234 461.7934430 NA
#> 2 rmst.trt 472.5726496 13.9339045 445.26269865 499.8826005 NA
#> 3 diff 98.8803419 47.0605014 6.64345409 191.1172297 2.101132
#> 4 log.ratio 0.2347587 0.1238482 -0.00797928 0.4774968 1.895536
#> p.value
#> 1 NA
#> 2 NA
#> 3 0.03562935
#> 4 0.05802142kmcurve_fast() builds the Kaplan-Meier curves of a data
set, and its plot() method can add the numbers at risk
below the curves.
kmcurve_fast(Surv(futime, fustat) ~ rx, data = ovarian) |>
plot(risk_table = TRUE, conf.style = "band")The functions can be chained with the native pipe |>
of R. A data frame piped into an estimation or testing function is used
as the data of its formula interface. The simulation functions take the
data, or the result of the previous step, as their first argument, and
cutoff.looks of analysis_fast() and
pairwise_fast(), like cutoff of
switch_fast(), also accepts a function of the data, so that
cutoffs from a rule of cutoff_fast() are computed inside
the chain. Here the final analysis is at 180 events or at month 36,
whichever comes first, and the nominal one-sided levels of the two looks
are only for illustration.
ovarian |> coxph_fast(Surv(futime, fustat) ~ rx, side = 1) |> as.data.frame()
#> term estimate std.error conf.low conf.high statistic p.value
#> 1 coef -0.59638 0.5869895 -1.746858 0.5540983 -1.015998 0.1548152
simdata_fast(nsim = 200, n = c(150, 150), a.time = c(0, 12),
a.rate = 300 / 12, e.median = list(12, 18),
d.hazard = 0.01, seed = 1) |>
analysis_fast(control = 1, side = 1,
cutoff.looks = function(x)
cutoff_fast(x, event.looks = c(120, 180),
max.time = c(NA, 36))) |>
simsummary_fast(p.col = "logrank.p", alpha = c(0.003, 0.024))
#> Group-Sequential Operating Characteristics (simsummary_fast)
#> Simulations: 200
#> Boundaries: nominal p-value on 'logrank.p'
#>
#> Stopping Boundaries: Look by Look
#> Look Info. Frac. Events (s) Sample (n) Nominal p Cum. Cross. Eff.
#> 1 0.67 120.0 300.0 0.0030 0.3000
#> 2 1.00 180.0 300.0 0.0240 0.7850
#>
#> Events, Sample Size, Dropouts, Pipeline and Analysis Times: Look by Look
#> Look Info. Frac. Sample (n) Events (s) Dropouts (d) Pipeline Analysis Time
#> 1 0.67 300.0 120.0 25.0 155.0 17.92
#> 2 1.00 300.0 180.0 38.0 82.0 29.18
#> Cross. Eff.
#> 0.3000
#> 0.4850
#>
#> Overall
#> Rejection rate (efficacy): 0.7850
#> Expected events at stop: 162.0
#> Expected sample size at stop: 300.0
#> Expected analysis time at stop: 25.79Several further vignettes cover the package in depth. Simulation
studies with the native pipe writes complete simulation studies as
chains of the functions above. Validation of FastSurvival
checks numerical agreement with established packages on a real
clinical-trial dataset. Speed comparison quantifies the
performance gain. Group sequential design with the simulation
trio demonstrates simdata_fast(),
analysis_fast(), and simsummary_fast() against
a gsDesign reference. Further applied vignettes work the simulation
functions through nonproportional-hazards, correlated multiple-endpoint,
multi-arm, multiregional, and treatment-switching settings, and
Using your own data generator analyzes data generated outside
the package with the same functions.
Collett, D. (2023). Modelling Survival Data in Medical Research (4th ed.). Chapman and Hall/CRC.