| cv_survdnn | R Documentation |
Performs cross-validation for a 'survdnn' model using the specified evaluation metrics.
cv_survdnn(
formula,
data,
times,
metrics = c("cindex", "ibs"),
folds = 5,
.seed = NULL,
.device = c("auto", "cpu", "cuda"),
.threads = NULL,
na_action = c("omit", "fail"),
verbose = TRUE,
...
)
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. |
.threads |
Optional positive integer. If provided, sets Torch CPU thread count before each fold fit via 'torch::torch_set_num_threads()'. |
na_action |
Character. How to handle missing values within each fold: '"omit"' drops incomplete rows; '"fail"' errors if any NA is present. |
verbose |
Logical; whether to print cross-validation progress and propagate verbose messages to fitting/evaluation in each fold (default: TRUE). |
... |
Additional arguments passed to [survdnn()]. |
A tibble containing metric values per fold and (optionally) per time point.
if (requireNamespace("torch", quietly = TRUE) && torch::torch_is_installed()) {
veteran <- survival::veteran
cv_survdnn(
survival::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
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.