Predicted values from a fitted object of class dnnsurv.

# S3 method for dnnsurv
predict(
  object,
  newdata,
  batch_size = 32L,
  verbose = 0L,
  steps = NULL,
  callbacks = NULL,
  type = c("survival", "risk", "all"),
  distr6 = FALSE,
  ...
)

Arguments

object

(dnnsurv(1))
Object of class inheriting from "dnnsurv".

newdata

(data.frame(1))
Testing data of data.frame like object, internally is coerced with stats::model.matrix(). If missing then training data from fitted object is used.

batch_size

(integer(1))
Passed to keras::predict.keras.engine.training.Model, elements in each batch.

verbose

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

steps

(integer(1))
Number of batches before evaluation finished, see keras::predict.keras.engine.training.Model.

callbacks

(list())
Optional callbacks to apply during prediction.

type

(character(1))
Type of predicted value. Choices are survival probabilities over all time-points in training data ("survival") or a relative risk ranking ("risk"), which is the negative mean survival time so higher rank implies higher risk of event, or both ("all").

distr6

(logical(1))
If FALSE (default) and type is "survival" or "all" returns matrix of survival probabilities, otherwise returns a distr6::Matdist().

...

ANY
Currently ignored.

Value

A numeric if type = "risk", a distr6::Matdist() (if distr6 = TRUE) and type = "survival"; a matrix if (distr6 = FALSE) and type = "survival" where entries are survival probabilities with rows of observations and columns are time-points; or a list combining above if type = "all".

Examples

# \donttest{
if (requireNamespaces(c("keras", "pseudo")))
  fit <- 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:
#> 
#> 

  # predict survival matrix and relative risks
  predict(fit, simsurvdata(10), type = "all")
#> Error in UseMethod("predict"): no applicable method for 'predict' applied to an object of class "function"

  # return as distribution
  if (requireNamespaces("distr6")) {
    predict(fit, simsurvdata(10), distr6 = TRUE)
  }
#> Error in UseMethod("predict"): no applicable method for 'predict' applied to an object of class "function"
# }