These functions use the existing fitting and prediction interface. No new modeling dependency or neural runtime is required. Here the independent censoring mechanism is known because the observations are generated.
set.seed(42)
x <- rnorm(400)
z <- rnorm(400)
failure <- exp(2 - .4 * x + .2 * z + rnorm(400, sd = .8))
censor <- rexp(400, .035)
d <- data.frame(time = pmin(failure, censor),
event = as.integer(failure <= censor), x, z)
train <- d[1:240, ]
test <- d[241:400, ]
f <- Surv(time, event) ~ x + z
cox <- surv_fit(f, train, "cox")
aft <- surv_fit(f, train, "aft", params = list(distribution = "lognormal"))The difference is always model minus reference. A positive concordance difference favors the model; a negative Brier difference favors the model. The same assessment units are resampled for every model. This preserves pairing, unlike comparing two separate confidence intervals.
surv_compare(list(cox = cox, aft = aft), test,
reference = "cox", n_boot = 100, seed = 9)
#> model reference metric time estimate reference_estimate difference
#> 1 aft cox harrell NA 0.6985958 0.6972896 0.001306194
#> lower upper bootstrap_valid n events status message
#> 1 -0.001758363 0.005493453 100 160 118 okThe percentile interval conditions on the event models, selected
settings, and censoring fit. It does not include refitting uncertainty.
It is pointwise, not simultaneous across models, metrics or horizons.
Use more repetitions for final analyses. Repeated CV rows are not
independent test units and must not be passed to this test-case
bootstrap. The existing surv_validate() reports descriptive
differences across paired folds, not these intervals.
For IPCW metrics, the comparison uses one common reference
distribution. If the models have different training outcomes, supply
censoring_data or censoring_model explicitly.
Undefined bootstrap estimates are counted in
bootstrap_valid and are not replaced by zero.
surv_calibrate(aft, test, times = 5, type = "metrics",
n_boot = 100, seed = 9)
#> metric time estimate ideal lower upper n known events
#> 1 intercept 5 0.2548655 0 -0.1289728 0.5842574 160 141 57
#> 2 slope 5 1.2412438 1 0.7574730 1.8230920 160 141 57
#> effective_n bootstrap_valid status message
#> 1 140.9173 100 ok
#> 2 140.9173 100 okFor failure probability \(p_i(t)=1-\widehat S(t\mid x_i)\), the intercept fit uses \(\operatorname{logit}\Pr(T_i\leq t)=a+\operatorname{logit}p_i(t)\). The slope comes from the separate fit \(\operatorname{logit}\Pr(T_i\leq t)=a+b\operatorname{logit}p_i(t)\). The ideal intercept and slope are zero and one. The fits use cases weighted by \(1/\widehat G(Y_i-)\) and controls by \(1/\widehat G(t)\), with zero weight for earlier censorings. They therefore require independent censoring for marginal G, or suitable conditional assumptions for a supplied G model. G is estimated on training/reference observations, never these test outcomes.
Exact zero/one probabilities, separation, constant logits and sparse
events are diagnosed. The procedure does not clip probabilities or
recalibrate the prediction model. Bootstrap intervals resample test
units with event/G fits fixed. The grouped calibration plot remains the
default type = "groups".
stack <- surv_stack(f, train, methods = c("cox", "aft"),
params = list(aft = list(distribution = "lognormal")),
times = c(3, 5, 8), folds = 3, seed = 9)
stack$weights
#> cox aft
#> 9.093126e-09 1.000000e+00
surv_predict(stack, test[1:2, ], "survival", times = c(3, 5, 8))
#> t=3 t=5 t=8
#> [1,] 0.9406636 0.8304912 0.6554718
#> [2,] 0.7100934 0.4798208 0.2720664
surv_compare(list(cox = cox, aft = aft, stack = stack), test,
metrics = c("harrell", "brier"), times = 5)
#> model metric time estimate lower upper n events status message
#> 1 cox harrell NA 0.6972896 NA NA 160 118 ok
#> 2 cox brier 5 0.2044021 NA NA 160 118 ok
#> 3 aft harrell NA 0.6985958 NA NA 160 118 ok
#> 4 aft brier 5 0.2002141 NA NA 160 118 ok
#> 5 stack harrell NA 0.6985958 NA NA 160 118 ok
#> 6 stack brier 5 0.2002141 NA NA 160 118 okEach training observation receives survival predictions from models
fitted without that observation. Preprocessing and G estimation are
repeated in each fold. If grids are supplied, their
Harrell-C tuning is performed on inner folds of that training sample.
The final base models are fitted on all training observations.
The weights minimize average out-of-fold IPCW Brier loss over the explicit horizons, subject to \(w_m\geq0\) and \(\sum_m w_m=1\). The resulting curve is \(\widehat S_{stack}(t\mid x)=\sum_m w_m\widehat S_m(t\mid x)\). The weights do not vary with time, so probability bounds and nonincreasing curves are preserved. They are not variable-importance measures and can be nonunique when component curves agree. A convex solver and an independent first-order bound check numerical optimality.
The OOF objective chooses weights; it is not an independent
performance estimate of the combined model. Evaluate the entire
procedure on a separate test sample or inside an outer validation loop.
Stacking currently accepts one complete stratified partition, not
grouped or temporal folds. Risk-only models, including the SVM
objectives, cannot be mixed with survival curves. Failures or
unsupported censoring horizons stop fitting; no learner or row is
silently removed. Risk prediction is negative restricted mean,
integrated over zero plus the declared grid. It is not a Cox log hazard
or a lifetime median. Supported reliability summaries remain available
through surv_reliability().