Scores survival predictions in one of three ways:
- Resampled
evaluate(fit)orevaluate(formula, data, model)refits the learner on each training split ofresamplingand scores it on the held-out split (internal validation).- New data
evaluate(fit, newdata = test)scores a fitted learner on data it was not trained on (external or temporal validation).- Supplied predictions
evaluate(S, y = Surv(time, status))scores ann x length(times)matrix of survival probabilities produced elsewhere, for example by another package.
Usage
evaluate(object, ...)
# S3 method for class 'survalis_fit'
evaluate(
object,
newdata = NULL,
times = NULL,
resampling = cv(),
metrics = c("cindex", "ibs"),
ncores = 1,
...
)
# S3 method for class 'formula'
evaluate(
object,
data,
model,
spec = list(),
times = NULL,
resampling = cv(),
metrics = c("cindex", "ibs"),
ncores = 1,
...
)
# S3 method for class 'matrix'
evaluate(object, y, times = NULL, metrics = c("cindex", "ibs"), ...)Arguments
- object
A
survalis_fitfromfit(), a survivalformula, or a numeric matrix of survival probabilities (rows = subjects, columns = times).- ...
Unused.
- newdata
When
objectis asurvalis_fit: optional data frame with the outcome columns. If given, the fit is scored on it once andresamplingis ignored.- times
Evaluation grid.
NULLpicks a grid from the data quantiles and records it; for a matrix,NULLreads the"times"attribute or column names of the form"t=<time>".- resampling
A resampling spec from
cv(),holdout(),groupcv()orbootstrap()(defaultcv()).- metrics
Character vector from
listmetrics()$metric."brier","ece","survacc"and range scores such as"range:0.05-0.20"require a singletimesvalue (seedwscore()).- ncores
Cores for the split loop (default
1).- data
When
objectis a formula: the data frame.- model
When
objectis a formula: a learner id (listlearners()$learner) or a custom learner (seefit()).- spec
When
objectis a formula: engine arguments (named list).- y
When
objectis a matrix: asurvival::Surv()object with one entry per row ofobject.
Value
A survalis_eval object: per_split (long data frame), summary
(mean / sd / se / 95% interval per metric), times, resampling (NULL
when scored once), metrics, model.
Examples
m <- fit(Surv(time, status) ~ age + karno + celltype, veteran, "ranger",
spec = list(num.trees = 100))
evaluate(m, times = c(90, 180, 365), resampling = cv(3))
#> <survalis_eval> model = ranger
#> <survalis_resampling> 3-fold CV, strata = status
#> grid: 3 times in [90, 365]
#> cindex 0.6114 (sd 0.0399, 95% [0.5662, 0.6566], n = 3)
#> ibs 0.1797 (sd 0.0150, 95% [0.1626, 0.1967], n = 3)
# train / test split
idx <- seq_len(100)
m_tr <- fit(Surv(time, status) ~ age + karno, veteran[idx, ], "coxph")
evaluate(m_tr, newdata = veteran[-idx, ], times = c(90, 180))
#> <survalis_eval> model = coxph
#> scored once on 37 subjects (no resampling)
#> grid: 2 times in [90, 180]
#> cindex 0.7554
#> ibs 0.1798
# predictions from anywhere
S <- predict(m_tr, veteran[-idx, ], times = c(90, 180))
evaluate(S, y = Surv(veteran$time[-idx], veteran$status[-idx]))
#> <survalis_eval> model = supplied predictions
#> scored once on 37 subjects (no resampling)
#> grid: 2 times in [90, 180]
#> cindex 0.7554
#> ibs 0.1798