View source: R/predict.flexsurvreg.R
predict.flexsurvreg | R Documentation |
Predict outcomes from flexible survival models at the covariate values
specified in newdata
.
## 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),
...
)
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. |
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.
Matthew T. Warkentin (https://github.com/mattwarkentin)
summary.flexsurvreg
,
residuals.flexsurvreg
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.