predict.flexsurvreg {flexsurv} | R Documentation |
Predictions from flexible survival models
Description
Predict outcomes from flexible survival models at the covariate values
specified in newdata
.
Usage
## 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 |
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 If |
type |
Character vector for the type of predictions desired.
|
times |
Vector of time horizons at which to compute fitted values.
Only applies when If not specified, predictions for For |
start |
Optional left-truncation time or times. The returned
survival, hazard, or cumulative hazard will be conditioned on survival up
to this time. |
conf.int |
Logical. Should confidence intervals be returned?
Default is |
conf.level |
Width of symmetric confidence intervals, relative to 1. |
se.fit |
Logical. Should standard errors of fitted values be returned?
Default is |
p |
Vector of quantiles at which to return fitted values when
|
... |
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.
This function is a wrapper around summary.flexsurvreg
,
designed to help flexsurv to integrate with the "tidymodels"
ecosystem, in particular the censored package.
summary.flexsurvreg
returns the same results but in a more
conventional format.
Author(s)
Matthew T. Warkentin (https://github.com/mattwarkentin)
See Also
summary.flexsurvreg
,
residuals.flexsurvreg
Examples
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)