survdnn: Deep Neural Networks for Survival Analysis in R
Cox, AFT, and CoxTime losses with a formula interface, cross-validation, and calibration, powered by torch
Imad El Badisy
2025-10-01
Survival analysis has traditionally been dominated by the Cox proportional hazards model and its semi-parametric extensions. Deep learning offers an alternative: one that can capture non-linear covariate effects and complex interactions without manual feature engineering. survdnn brings that capability to R via the torch backend, with the same formula-based interface that R users already know.
What is survdnn?
survdnn (v0.7.6) trains multilayer perceptrons for right-censored survival data. It supports four loss functions, built-in cross-validation, hyperparameter tuning, survival curve prediction, and standard evaluation metrics.
p <-plot(fit, newdata = lung[1:5, ], times = times)ggplot2::ggsave("featured.png", p, width =7, height =4.5, dpi =150)p
Evaluation
evaluate_survdnn() computes the concordance index and integrated Brier score from the fitted model:
evaluate_survdnn(fit, metrics =c("cindex", "ibs"), times =seq(100, 800, by =200), newdata = lung)
# A tibble: 2 × 2
metric value
<chr> <dbl>
1 cindex 0.689
2 ibs 0.162
Hyperparameter tuning with cross-validation
tune_survdnn() runs a grid search over the hyperparameter space with K-fold cross-validation. param_grid is a named list crossed via tidyr::crossing(), and must include hidden, lr, activation, epochs, .loss_fn, and loss_name:
Under the hood, survdnn() builds an MLP via build_dnn(): linear layers with optional batch normalization and dropout between each hidden layer, terminating in a single linear output. The torch optimizer (Adam by default) is configurable via optimizer and optim_args.
Methodological background
survdnn’s design, loss functions, and benchmarks against classical and machine learning survival models are described in El Badisy (2026), “SurvDNN: Survival Deep Learning Models for Tabular Data”, The R Journal, RJ-2026-008.