DNNSurv neural fits a neural network based on pseudo-conditional survival probabilities.

dnnsurv(
  formula = NULL,
  data = NULL,
  reverse = FALSE,
  time_variable = "time",
  status_variable = "status",
  x = NULL,
  y = NULL,
  cutpoints = NULL,
  cuts = 5L,
  custom_model = NULL,
  loss_weights = NULL,
  weighted_metrics = NULL,
  optimizer = "adam",
  early_stopping = FALSE,
  min_delta = 0,
  patience = 0L,
  verbose = 0L,
  baseline = NULL,
  restore_best_weights = FALSE,
  batch_size = 32L,
  epochs = 10L,
  validation_split = 0,
  shuffle = TRUE,
  sample_weight = NULL,
  initial_epoch = 0L,
  steps_per_epoch = NULL,
  validation_steps = NULL,
  ...
)

Arguments

formula

(formula(1))
Object specifying the model fit, left-hand-side of formula should describe a survival::Surv() object.

data

(data.frame(1))
Training data of data.frame like object, internally is coerced with stats::model.matrix().

reverse

(logical(1))
If TRUE fits estimator on censoring distribution, otherwise (default) survival distribution.

time_variable

(character(1))
Alternative method to call the function. Name of the 'time' variable, required if formula. or x and Y not given.

status_variable

(character(1))
Alternative method to call the function. Name of the 'status' variable, required if formula or x and Y not given.

x

(data.frame(1))
Alternative method to call the function. Required if formula, time_variable and status_variable not given. Data frame like object of features which is internally coerced with model.matrix.

y

([survival::Surv()])
Alternative method to call the function. Required if formula, time_variable and status_variable not given. Survival outcome of right-censored observations.

cutpoints

(numeric())
Points at which to cut survival time into discrete points.

cuts

(integer(1))
If cutpoints not provided then number of equally spaced points at which to cut survival time.

custom_model

(keras.engine.training.Model(1))
Optional custom architecture built with build_keras_net or directly with keras. Output layer should be of length 1 input is number of features plus number of cuts.

loss_weights, weighted_metrics

See keras::compile.keras.engine.training.Model.

optimizer

(character(1))
See get_keras_optimizer.

early_stopping

(logical(1))
If TRUE then early stopping callback is included.

min_delta, patience, baseline, restore_best_weights

See keras::callback_early_stopping.

verbose

(integer(1))
Level of verbosity for printing, 0 or 1.

batch_size, epochs, validation_split, shuffle, sample_weight, initial_epoch, steps_per_epoch, validation_steps

See keras::fit.keras.engine.training.Model. # nolint

...

ANY
Passed to get_keras_optimizer.

Value

An object of class survivalmodel.

Details

Code for generating the conditional probabilities and pre-processing data is taken from https://github.com/lilizhaoUM/DNNSurv.

References

Zhao, L., & Feng, D. (2020). DNNSurv: Deep Neural Networks for Survival Analysis Using Pseudo Values. https://arxiv.org/abs/1908.02337

Examples

# \donttest{
if (requireNamespaces(c("keras", "pseudo")))
  # all defaults
  dnnsurv(data = simsurvdata(10))
#> List of 22
#>  $ python              : chr "/usr/local/bin/python3"
#>  $ libpython           : chr "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib"
#>  $ pythonhome          : chr "/Library/Frameworks/Python.framework/Versions/3.12:/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ pythonpath          : chr "/Users/runner/work/_temp/Library/reticulate/config:/Library/Frameworks/Python.framework/Versions/3.12/lib/pytho"| __truncated__
#>  $ prefix              : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ exec_prefix         : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ base_exec_prefix    : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ virtualenv          : chr ""
#>  $ virtualenv_activate : chr ""
#>  $ executable          : chr "/usr/local/bin/python3"
#>  $ base_executable     : chr "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
#>  $ version_string      : chr "3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]"
#>  $ version             : chr "3.12"
#>  $ architecture        : chr "64bit"
#>  $ anaconda            : logi FALSE
#>  $ conda               : chr "False"
#>  $ numpy               : NULL
#>  $ required_module     : chr "tensorflow"
#>  $ required_module_path: NULL
#>  $ available           : logi TRUE
#>  $ python_versions     : chr [1:2] "/usr/local/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"
#>  $ forced              : NULL
#>  - attr(*, "class")= chr "py_config"
#> Error: Python module tensorflow.keras was not found.
#> 
#> Detected Python configuration:
#> 
#> 

  # setting common parameters
  dnnsurv(time_variable = "time", status_variable = "status", data = simsurvdata(10),
          early_stopping = TRUE, epochs = 100L, validation_split = 0.3)
#> List of 22
#>  $ python              : chr "/usr/local/bin/python3"
#>  $ libpython           : chr "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib"
#>  $ pythonhome          : chr "/Library/Frameworks/Python.framework/Versions/3.12:/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ pythonpath          : chr "/Users/runner/work/_temp/Library/reticulate/config:/Library/Frameworks/Python.framework/Versions/3.12/lib/pytho"| __truncated__
#>  $ prefix              : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ exec_prefix         : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ base_exec_prefix    : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ virtualenv          : chr ""
#>  $ virtualenv_activate : chr ""
#>  $ executable          : chr "/usr/local/bin/python3"
#>  $ base_executable     : chr "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
#>  $ version_string      : chr "3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]"
#>  $ version             : chr "3.12"
#>  $ architecture        : chr "64bit"
#>  $ anaconda            : logi FALSE
#>  $ conda               : chr "False"
#>  $ numpy               : NULL
#>  $ required_module     : chr "tensorflow"
#>  $ required_module_path: NULL
#>  $ available           : logi TRUE
#>  $ python_versions     : chr [1:2] "/usr/local/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"
#>  $ forced              : NULL
#>  - attr(*, "class")= chr "py_config"
#> Error: Python module tensorflow.keras was not found.
#> 
#> Detected Python configuration:
#> 
#> 

  # custom model
  library(keras)
#> 
#> Attaching package: ‘keras’
#> The following object is masked from ‘package:survivalmodels’:
#> 
#>     install_keras
  cuts <- 10
  df <- simsurvdata(50)
  # shape = features + cuts
  input <- layer_input(shape = c(3L + cuts), name = 'input')
#> List of 22
#>  $ python              : chr "/usr/local/bin/python3"
#>  $ libpython           : chr "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib"
#>  $ pythonhome          : chr "/Library/Frameworks/Python.framework/Versions/3.12:/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ pythonpath          : chr "/Users/runner/work/_temp/Library/reticulate/config:/Library/Frameworks/Python.framework/Versions/3.12/lib/pytho"| __truncated__
#>  $ prefix              : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ exec_prefix         : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ base_exec_prefix    : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ virtualenv          : chr ""
#>  $ virtualenv_activate : chr ""
#>  $ executable          : chr "/usr/local/bin/python3"
#>  $ base_executable     : chr "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
#>  $ version_string      : chr "3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]"
#>  $ version             : chr "3.12"
#>  $ architecture        : chr "64bit"
#>  $ anaconda            : logi FALSE
#>  $ conda               : chr "False"
#>  $ numpy               : NULL
#>  $ required_module     : chr "tensorflow"
#>  $ required_module_path: NULL
#>  $ available           : logi TRUE
#>  $ python_versions     : chr [1:2] "/usr/local/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"
#>  $ forced              : NULL
#>  - attr(*, "class")= chr "py_config"
#> Error: Python module tensorflow.keras was not found.
#> 
#> Detected Python configuration:
#> 
#> 
  output <- input %>%
     layer_dense(units = 4L, use_bias = TRUE) %>%
     layer_dense(units = 1L, use_bias = TRUE ) %>%
     layer_activation(activation="sigmoid")
#> List of 22
#>  $ python              : chr "/usr/local/bin/python3"
#>  $ libpython           : chr "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib"
#>  $ pythonhome          : chr "/Library/Frameworks/Python.framework/Versions/3.12:/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ pythonpath          : chr "/Users/runner/work/_temp/Library/reticulate/config:/Library/Frameworks/Python.framework/Versions/3.12/lib/pytho"| __truncated__
#>  $ prefix              : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ exec_prefix         : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ base_exec_prefix    : chr "/Library/Frameworks/Python.framework/Versions/3.12"
#>  $ virtualenv          : chr ""
#>  $ virtualenv_activate : chr ""
#>  $ executable          : chr "/usr/local/bin/python3"
#>  $ base_executable     : chr "/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12"
#>  $ version_string      : chr "3.12.2 (v3.12.2:6abddd9f6a, Feb  6 2024, 17:02:06) [Clang 13.0.0 (clang-1300.0.29.30)]"
#>  $ version             : chr "3.12"
#>  $ architecture        : chr "64bit"
#>  $ anaconda            : logi FALSE
#>  $ conda               : chr "False"
#>  $ numpy               : NULL
#>  $ required_module     : chr "tensorflow"
#>  $ required_module_path: NULL
#>  $ available           : logi TRUE
#>  $ python_versions     : chr [1:2] "/usr/local/bin/python3" "/Library/Frameworks/Python.framework/Versions/3.12/bin/python"
#>  $ forced              : NULL
#>  - attr(*, "class")= chr "py_config"
#> Error: Python module tensorflow.keras was not found.
#> 
#> Detected Python configuration:
#> 
#> 

  model <- keras_model(input, output)
#> Error in if (tf_version() < "2.4") names(inputs) <- names(outputs) <- NULL: argument is of length zero
  class(model)
#> Error in eval(expr, envir, enclos): object 'model' not found

  dnnsurv(custom_model = model, time_variable = "time",
          status_variable = "status", data = df, cuts = cuts)
#> Error in eval(expr, envir, enclos): object 'model' not found

# }