Learn R Programming

survdnn (version 0.7.5)

cv_survdnn: K-Fold Cross-Validation for survdnn Models

Description

Performs cross-validation for a `survdnn` model using the specified evaluation metrics.

Usage

cv_survdnn(
  formula,
  data,
  times,
  metrics = c("cindex", "ibs"),
  folds = 5,
  .seed = NULL,
  .device = c("auto", "cpu", "cuda"),
  na_action = c("omit", "fail"),
  ...
)

Value

A tibble containing metric values per fold and (optionally) per time point.

Arguments

formula

A survival formula, e.g., `Surv(time, status) ~ x1 + x2`.

data

A data frame.

times

A numeric vector of evaluation time points.

metrics

A character vector: any of `"cindex"`, `"brier"`, `"ibs"`.

folds

Integer. Number of folds to use.

.seed

Optional. Set random seed for reproducibility.

.device

Character string indicating the computation device used when fitting the models in each fold. One of `"auto"`, `"cpu"`, or `"cuda"`. `"auto"` uses CUDA if available, otherwise falls back to CPU.

na_action

Character. How to handle missing values within each fold: `"omit"` drops incomplete rows; `"fail"` errors if any NA is present.

...

Additional arguments passed to [survdnn()].

Examples

Run this code
# \donttest{
library(survival)
data(veteran)
cv_survdnn(
  Surv(time, status) ~ age + karno + celltype,
  data = veteran,
  times = c(30, 90, 180),
  metrics = "ibs",
  folds = 3,
  .seed = 42,
  hidden = c(16, 8),
  epochs = 5
)
# }

Run the code above in your browser using DataLab