predict.parametric: Predict method for Parametric Model

View source: R/parametric.R

predict.parametricR Documentation

Predict method for Parametric Model

Description

Predicted values from a fitted Parametric survival model.

Usage

## S3 method for class 'parametric'
predict(
  object,
  newdata,
  form = c("aft", "ph", "tobit", "po"),
  times = NULL,
  type = c("survival", "risk", "all"),
  distr6 = FALSE,
  ntime = 150,
  round_time = 2,
  ...
)

Arguments

object

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

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.

form

(character(1))
The form of the predicted distribution, see details for options.

times

(numeric())
Times at which to evaluate the estimator. If NULL (default) then evaluated at all unique times in the training set.

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 sum of the predicted cumulative hazard function 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::Distribution().

ntime

(numeric(1))
Number of unique time-points in the training set, default is 150.

round_time

(numeric(1))
Number of decimal places to round time-points to, default is 2, set to FALSE for no rounding.

...

ANY
Currently ignored.

Details

The form parameter determines how the distribution is created. Options are:

  • Accelerated failure time ("aft")

    h(t) = h_0(\frac{t}{exp(lp)})exp(-lp)

  • Proportional Hazards ("ph")

    h(t) = h_0(t)exp(lp)

  • Tobit ("tobit")

    h(t) = \Phi(\frac{t - lp}{scale})

  • Proportional odds ("po")

    h(t) = \frac{h_0(t)}{1 + (exp(lp)-1)S_0(t)}

where h_0,S_0 are the estimated baseline hazard and survival functions (in this case with a given parametric form), lp is the predicted linear predictor calculated using the formula lp = \hat{\beta} X_{new} where X_{new} are the variables in the test data set and \hat{\beta} are the coefficients from the fitted parametric survival model (object). \Phi is the cdf of a N(0, 1) distribution, and scale is the fitted scale parameter.

Value

A numeric if type = "risk", a distr6::Distribution() (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

if (requireNamespaces(c("distr6", "survival"))) {
  library(survival)

  set.seed(42)
  train <- simsurvdata(10)
  test <- simsurvdata(5)
  fit <- parametric(Surv(time, status) ~ ., data = train)

  # Return a discrete distribution survival matrix
  predict_distr <- predict(fit, newdata = test)
  predict_distr

  # Return a relative risk ranking with type = "risk"
  predict(fit, newdata = test, type = "risk")

  # Or survival probabilities and a rank
  predict(fit, newdata = test, type = "all", distr6 = TRUE)
}

RaphaelS1/survivalmodels documentation built on July 5, 2024, 10:17 a.m.