Predict Method for Parametric Proportional Hazards Survival Models
Source:R/predict.streg.R
predict.streg.Rd
Obtain model-based predictions from a parametric proportional hazards survival model fitted by streg()
.
Usage
# S3 method for streg
predict(object, newdata = NULL, type = "xb", se.fit = FALSE, ...)
Arguments
- object
A fitted
streg()
object.- newdata
Optionally, a data frame in which to look for variables with which to predict. If
NULL
(the default), predictions will be computed for the data used to fit the model. In this scenario, passing anstreg()
model fitted with the argumentx = TRUE
is required.- type
The type of prediction required. The default
"xb"
is to return the linear predictor. Other possible predictions are the hazard function (type = "hazard"
) and the survival function (type = "survival"
).- se.fit
Logical switch indicating if standard errors are required.
- ...
Not used.
Value
If se.fit = FALSE
, a vector with the required predictions.
If se.fit = TRUE
a data.frame
is returned with a column for the predictions (named fit
) and a column for the fitted standard errors (named se.fit
).
Note
Standard errors are estimated using the numerical delta method, as implemented in rstpm2::predictnl()
--- which is equivalent, in principle --- to Stata's predictnl
command.
Examples
library(streg)
data("kva", package = "streg")
# Fit a model
fit <- streg(Surv(failtime, event) ~ load + bearings, data = kva, distribution = "exp", x = TRUE)
# Predict the hazard for each subject
predict(fit, type = "surv")
#> [1] 0.4534698 0.4110771 0.3530038 0.3493923 0.2940474 0.3103658 0.3436591
#> [8] 0.4378607 0.3416486 0.3055314 0.4485186 0.4156529
# Predict the survival probability, including a standard error for the fitted value
predict(fit, type = "surv", se.fit = TRUE)
#> fit se.fit
#> 1 0.4534698 0.2160007
#> 2 0.4110771 0.2201323
#> 3 0.3530038 0.1790433
#> 4 0.3493923 0.1789790
#> 5 0.2940474 0.1503516
#> 6 0.3103658 0.1516996
#> 7 0.3436591 0.1533435
#> 8 0.4378607 0.1510580
#> 9 0.3416486 0.1787424
#> 10 0.3055314 0.1764592
#> 11 0.4485186 0.2166310
#> 12 0.4156529 0.2197878
# Predictions for a new dataset
nd <- data.frame(failtime = 30, event = 1, load = 10, bearings = 3)
predict(fit, newdata = nd, type = "surv")
#> [1] 0.913497
predict(fit, newdata = nd, type = "surv", se.fit = TRUE)
#> fit se.fit
#> 1 0.913497 0.1320159