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"),
verbose = TRUE
)
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 Adam 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"'. |
verbose |
Logical; whether to print loss progress every 50 epochs (default: TRUE). |
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.
set.seed(123)
df <- data.frame(
time = rexp(100, rate = 0.1),
status = rbinom(100, 1, 0.7),
x1 = rnorm(100),
x2 = rbinom(100, 1, 0.5)
)
mod <- survdnn(Surv(time, status) ~ x1 + x2, data = df, epochs = 5
, loss = "cox", verbose = FALSE)
mod$final_loss
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.