Predict outcomes from flexible survival models at the covariate values
specified in newdata
.
# S3 method for 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.
fitg <- flexsurvreg(formula = Surv(futime, fustat) ~ age, data = ovarian, dist = "gengamma") ## Simplest prediction: mean or median, for covariates defined by original dataset predict(fitg)#> # A tibble: 26 × 1 #> .pred #> <dbl> #> 1 246. #> 2 204. #> 3 411. #> 4 1295. #> 5 1687. #> 6 990. #> 7 947. #> 8 734. #> 9 503. #> 10 1105. #> # … with 16 more rows#> # A tibble: 26 × 2 #> .quantile .pred #> <dbl> <dbl> #> 1 0.5 194. #> 2 0.5 161. #> 3 0.5 325. #> 4 0.5 1022. #> 5 0.5 1331. #> 6 0.5 781. #> 7 0.5 747. #> 8 0.5 579. #> 9 0.5 397. #> 10 0.5 872. #> # … with 16 more rows## Simple prediction for user-defined covariate values predict(fitg, newdata = data.frame(age = c(40, 50, 60)))#> # A tibble: 3 × 1 #> .pred #> <dbl> #> 1 4169. #> 2 1738. #> 3 724.#> # A tibble: 3 × 2 #> .quantile .pred #> <dbl> <dbl> #> 1 0.5 3291. #> 2 0.5 1372. #> 3 0.5 572.#>#> # A tibble: 52 × 2 #> .time .pred #> <dbl> <dbl> #> 1 600 0.0548 #> 2 800 0.0202 #> 3 600 0.0292 #> 4 800 0.00926 #> 5 600 0.200 #> 6 800 0.104 #> 7 600 0.751 #> 8 800 0.624 #> 9 600 0.841 #> 10 800 0.742 #> # … with 42 more rows