predict.flexsurvreg: Predictions from flexible survival models

Description Usage Arguments Value See Also Examples

View source: R/predict.flexsurvreg.R

Description

Predict outcomes from flexible survival models at the covariate values specified in newdata.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## S3 method for class 'flexsurvreg'
predict(
  object,
  newdata,
  type = "response",
  times,
  start = 0,
  conf.int = FALSE,
  conf.level = 0.95,
  se.fit = FALSE,
  p = c(0.1, 0.9),
  ...
)

Arguments

object

Output from flexsurvreg or flexsurvspline, representing a fitted survival model object.

newdata

Data frame containing covariate values at which to produce fitted values. There must be a column for every covariate in the model formula used to fit object, and one row for every combination of covariate values at which to obtain the fitted predictions.

If newdata is omitted, then the original data used to fit the model are used, as extracted by model.frame(object).

type

Character vector for the type of predictions desired.

  • "response" for mean survival (the default)

  • "quantile" for quantiles of the survival distribution specified by p

  • "rmst" for restricted mean survival time

  • "survival" for survival probabilities

  • "cumhaz" for cumulative hazards

  • "hazard" for hazards

  • "link" for fitted values of the location parameter, analogous to the linear predictor in generalized linear models (type = "lp" and type = "linear" are acceptable synonyms)

times

Vector of time horizons at which to compute fitted values. Only applies when type is "survival", "cumhaz", "hazard", or "rmst". Will be silently ignored for all other types.

If not specified, predictions for "survival", "cumhaz", and "hazard" will be made at each observed event time in model.frame(object).

For "rmst", when times is not specified predictions will be made at the maximum observed event time from the data used to fit object. Specifying times = Inf is valid, and will return mean survival (equal to type = "response").

start

Optional left-truncation time or times. The returned survival, hazard, or cumulative hazard will be conditioned on survival up to this time. start must be length 1 or the same length as times.

conf.int

Logical. Should confidence intervals be returned? Default is FALSE.

conf.level

Width of symmetric confidence intervals, relative to 1.

se.fit

Logical. Should standard errors of fitted values be returned? Default is FALSE.

p

Vector of quantiles at which to return fitted values when type = "quantile". Default is c(0.1, 0.9).

...

Not currently used.

Value

A tibble with same number of rows as newdata and in the same order. If multiple predictions are requested, a tibble containing a single list-column of data frames.

For the list-column of data frames - the dimensions of each data frame will be identical. Rows are added for each value of times or p requested.

See Also

summary.flexsurvreg, residuals.flexsurvreg

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
fitg <- flexsurvreg(formula = Surv(futime, fustat) ~ age, data = ovarian, dist = "gengamma")

## Simplest prediction: mean or median, for covariates defined by original dataset
predict(fitg)
predict(fitg, type = "quantile", p = 0.5)

## Simple prediction for user-defined covariate values
predict(fitg, newdata = data.frame(age = c(40, 50, 60)))
predict(fitg, type = "quantile", p = 0.5, newdata = data.frame(age = c(40,50,60)))

## Predict multiple quantiles and unnest
require(tidyr)
pr <- predict(fitg, type = "survival", times = c(600, 800))
tidyr::unnest(pr, .pred)

flexsurv documentation built on Sept. 13, 2021, 5:07 p.m.