| survdnn | R Documentation |
Trains a deep neural network (DNN) to model right-censored survival data using one of the predefined loss functions: Cox, AFT, or Coxtime.
survdnn(
formula,
data,
hidden = c(32L, 16L),
activation = "relu",
lr = 1e-04,
epochs = 300L,
loss = c("cox", "cox_l2", "aft", "coxtime"),
optimizer = c("adam", "adamw", "sgd", "rmsprop", "adagrad"),
optim_args = list(),
verbose = TRUE,
dropout = 0.3,
batch_norm = TRUE,
callbacks = NULL,
.seed = NULL,
.device = c("auto", "cpu", "cuda"),
na_action = c("omit", "fail")
)
formula |
A survival formula of the form 'Surv(time, status) ~ predictors'. |
data |
A data frame containing the variables in the model. |
|
Integer vector. Sizes of the hidden layers (default: c(32, 16)). | |
activation |
Character string specifying the activation function to use in each layer. Supported options: '"relu"', '"leaky_relu"', '"tanh"', '"sigmoid"', '"gelu"', '"elu"', '"softplus"'. |
lr |
Learning rate for the optimizer (default: '1e-4'). |
epochs |
Number of training epochs (default: 300). |
loss |
Character name of the loss function to use. One of '"cox"', '"cox_l2"', '"aft"', or '"coxtime"'. |
optimizer |
Character string specifying the optimizer to use. One of '"adam"', '"adamw"', '"sgd"', '"rmsprop"', or '"adagrad"'. Defaults to '"adam"'. |
optim_args |
Optional named list of additional arguments passed to the underlying torch optimizer (e.g., 'list(weight_decay = 1e-4, momentum = 0.9)'). |
verbose |
Logical; whether to print loss progress every 50 epochs (default: TRUE). |
dropout |
Numeric between 0 and 1. Dropout rate applied after each hidden layer (default = 0.3). Set to 0 to disable dropout. |
batch_norm |
Logical; whether to add batch normalization after each hidden linear layer (default = TRUE). |
callbacks |
Optional list of callback functions. Each callback should have signature 'function(epoch, current)' and return TRUE if training should stop, FALSE otherwise. Used, for example, with [callback_early_stopping()]. |
.seed |
Optional integer. If provided, sets both R and torch random seeds for reproducible weight initialization, shuffling, and dropout. |
.device |
Character string indicating the computation device. One of '"auto"', '"cpu"', or '"cuda"'. '"auto"' uses CUDA if available, otherwise falls back to CPU. |
na_action |
Character. How to handle missing values in the model variables: '"omit"' drops incomplete rows (and reports how many were removed when 'verbose=TRUE'); '"fail"' stops with an error if any missing values are present. |
An object of class '"survdnn"' containing:
Trained 'nn_module' object.
Original survival formula.
Training data used for fitting.
Predictor variable names.
Column means of predictors.
Column standard deviations of predictors.
Vector of loss values per epoch.
Final training loss.
Loss function name used ("cox", "aft", etc.).
Activation function used.
Hidden layer sizes.
Learning rate.
Number of training epochs.
Optimizer name used.
List of optimizer arguments used.
Torch device used for training ('torch_device').
Learned global log(sigma) for 'loss="aft"'; 'NA_real_' otherwise.
AFT log-time location offset used for centering when 'loss="aft"'; 'NA_real_' otherwise.
Mean used to scale time for CoxTime; 'NA_real_' otherwise.
SD used to scale time for CoxTime; 'NA_real_' otherwise.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.