Evaluation and validation for right-censored outcomes

Define the prediction target

Write \(Y_i=\min(T_i,C_i)\) and \(\delta_i=I(T_i\leq C_i)\). A risk score \(r_i\) orders failures; \(\widehat S_i(t)\) estimates \(P(T_i>t\mid x_i)\). These outputs are not interchangeable. Risk-only models cannot be evaluated as probability models without an additional, explicitly trained calibration procedure.

d <- survival::veteran
set.seed(17)
id <- sample(seq_len(nrow(d)), 100)
train <- d[id, ]
test <- d[-id, ]
f <- Surv(time, status) ~ age + karno
fit <- surv_fit(f, train, "aft")
surv_score(fit, test)
#> [1] 0.7052469

Discrimination and probability accuracy

With \(a(r_i,r_j)=I(r_i>r_j)+\tfrac12 I(r_i=r_j)\), Harrell’s index estimates correct ordering among comparable pairs. It is not sensitivity, a percentage of correctly predicted failure times, or a calibration measure.

Let \(\widehat G\) be a marginal censoring Kaplan-Meier estimate. Truncated IPCW concordance uses \(w_i=\delta_i I(Y_i\leq\tau)/\widehat G(Y_i-)^2\):

\[ \widehat C_{\mathrm{IPCW}}(\tau)= \frac{\sum_{i,j}w_i I(Y_i<Y_j)a(r_i,r_j)} {\sum_{i,j}w_i I(Y_i<Y_j)}. \]

The implementation uses strict observed-time comparisons and half credit for tied risk scores. Declare tau; do not extend it into an unsupported censoring tail. The censoring assumptions still matter. Uno et al. (2011) motivate IPCW concordance.

For a horizon \(t\), cumulative/dynamic AUC compares failures by \(t\) with subjects surviving past \(t\), weighting observed cases and controls for censoring. Brier error evaluates probabilities instead:

\[ \widehat{BS}(t)=\frac1n\sum_{i=1}^n\left[ \frac{\delta_i I(Y_i\leq t)\widehat S_i(t)^2}{\widehat G(Y_i-)}+ \frac{I(Y_i>t)\{1-\widehat S_i(t)\}^2}{\widehat G(t)} \right]. \]

For a supplied grid spanning \([a,b]\),

\[ \widehat{IBS}_{[a,b]}=\frac1{b-a}\int_a^b\widehat{BS}(t)\,dt, \]

approximated by the trapezoidal rule. Report the interval and grid. Scores over different intervals are not automatically comparable. Discrimination and probability accuracy assess different targets, as discussed by Haider et al. (2020).

ev <- surv_evaluate(fit, test,
  metrics = c("harrell", "uno", "auc", "brier", "ibs"),
  times = c(30, 60, 90), tau = 90)
ev
#>    metric time  estimate lower upper  n events status message
#> 1 harrell   NA 0.7052469    NA    NA 37     36     ok        
#> 2     uno   90 0.7633206    NA    NA 37     36     ok        
#> 3     auc   30 0.8289756    NA    NA 37     36     ok        
#> 4     auc   60 0.7699459    NA    NA 37     36     ok        
#> 5     auc   90 0.8299380    NA    NA 37     36     ok        
#> 6   brier   30 0.1201427    NA    NA 37     36     ok        
#> 7   brier   60 0.1683826    NA    NA 37     36     ok        
#> 8   brier   90 0.1850109    NA    NA 37     36     ok        
#> 9     ibs   NA 0.1604797    NA    NA 37     36     ok
plot(ev, metric = "brier")

By default, G uses stored training outcomes, not the external test. The censoring mechanism must be compatible between samples. Users can provide censoring_data explicitly, or a reference surv_censor_fit() via censoring_model for marginal, stratified or Cox \(G(t\mid x)\). Inspect status/message fields and censoring settings attached to the evaluation. Unstable small G values are not silently clipped.

Under \(\delta=I(T\leq C)\), tied failures precede censoring. With risk count \(R(u)\), failures \(d_E(u)\) and censorings \(d_C(u)\), the reverse KM is \(\widehat G(t)=\prod_{u\leq t}\{1-d_C(u)/(R(u)-d_E(u))\}\), with no decrement when there are no censorings. Simply swapping the event indicator gives the wrong censoring risk set at such ties. This convention agrees with prodlim’s documented reverse estimator.

Calibration and uncertainty

Grouped calibration compares mean predicted survival with within-group KM at a specified horizon. Tied predictions can reduce the number of distinct groups. Small groups and few subjects at risk make calibration unstable. The diagnostic does not retrain or recalibrate the model.

cal <- surv_calibrate(fit, test, times = 60, groups = 3)
#> Warning: Low support or collapsed groups in survival calibration; inspect
#> status and message.
cal
#>   time group predicted  observed     lower     upper  n events n_risk
#> 1   60     1 0.4019137 0.5000000 0.2084771 0.7360731 12      6      6
#> 2   60     2 0.6431706 0.6923077 0.3733635 0.8717501 13      4      9
#> 3   60     3 0.7713474 0.9166667 0.5389772 0.9878256 12      1     11
#>        status                         message
#> 1          ok                                
#> 2          ok                                
#> 3 low_support Fewer than 3 events by horizon.
plot(cal)

An explicit censoring fit makes the calibration assumption consistent with probability evaluation:

g <- surv_censor_fit(f, train, method = "cox")
conditional_cal <- surv_calibrate(fit, test, times = 60, groups = 3,
  censoring_model = g, n_boot = 100, seed = 14)
#> Warning: Low support or collapsed groups in IPCW calibration; inspect status
#> and message.
conditional_cal
#>   time group predicted  observed     lower     upper  n events n_risk
#> 1   60     1 0.4019137 0.5016142 0.2073431 0.7514831 12      6      6
#> 2   60     2 0.6431706 0.6929878 0.5383166 0.9232341 13      4      9
#> 3   60     3 0.7713474 0.9160202 0.6650618 1.0000000 12      1     11
#>   effective_n bootstrap_valid      status                         message
#> 1    11.99978             100          ok                                
#> 2    12.99945             100          ok                                
#> 3    11.99928             100 low_support Fewer than 3 events by horizon.

For each group, observed survival is normalized IPCW control mass divided by weighted case plus control mass. Event weights use \(G(Y_i-\mid x_i)\) and controls use \(G(t\mid x_i)\). This estimator is not a within-group KM curve. Its bootstrap fixes both fitted models and the original groups. Effective sample size, sparse events and undefined replicates remain visible.

surv_evaluate(..., n_boot = 200) resamples evaluation cases while keeping the model and censoring KM fixed. Percentile intervals are conditional on those fits, not uncertainty of the full training/tuning process. For dependent rows, independent case bootstrap intervals are inappropriate; respect sampling units.

Shared and nested resampling

splits <- surv_resamples(f, train, folds = 3, seed = 11)
tuned <- surv_tune(f, train, "aft",
  grid = list(distribution = c("weibull", "lognormal")), resamples = splits)
tuned$results
#>   candidate distribution mean_cindex  sd_cindex failed_folds seconds
#> 1         1      weibull   0.6911427 0.07028425            0    0.05
#> 2         2    lognormal   0.6830966 0.07360152            0    0.00
#>   mean_estimate sd_estimate  metric
#> 1     0.6911427  0.07028425 harrell
#> 2     0.6830966  0.07360152 harrell
surv_score(tuned, test)
#> [1] 0.7052469

validated <- surv_validate(f, train, methods = c("km", "cox", "aft"),
  grids = list(aft = list(distribution = c("weibull", "lognormal"))),
  resamples = splits, inner_folds = 3, seed = 12, metric = "harrell")
validated$summary
#>   method  metric time n_total n_valid n_paired      mean         sd mean_common
#> 1     km harrell   NA       3       3        3 0.5000000 0.00000000   0.5000000
#> 2    cox harrell   NA       3       3        3 0.6930439 0.07161832   0.6930439
#> 3    aft harrell   NA       3       3        3 0.6917764 0.07071470   0.6917764
#>    sd_common
#> 1 0.00000000
#> 2 0.07161832
#> 3 0.07071470

Each outer assessment is excluded from tuning and preprocessing. Inner splits are generated within outer training. Failed candidates and warnings remain inspectable. A tuning criterion is not final held-out performance. metric selects inner candidates independently of the order of metrics. Use selection_time for one AUC/Brier tuning horizon when reporting several horizons. A missing required horizon is rejected before fitting. With grid = NULL, only one fixed configuration is evaluated; summary(tuned) states that no hyperparameter search took place.

Grouped rows and future deployment require grouped or forward temporal designs. The inner design must preserve the outer design, not silently switch to random K-fold. Fold dispersion is descriptive, not an independent-sample standard error. Temporal ordering alone does not ensure that labels had already become known at a historical deployment date. Construct feature availability, follow-up cutoffs and any needed embargo before validating. Do not order by the observed survival response and call that prospective deployment validation.

impute = "median" learns numeric medians and categorical modes separately within each fold, before formula transformations. Missing outcomes, entirely missing training predictors and unsupported new levels are rejected. A final test set is never used to stop neural training early.