predict.orsf_fit {aorsf}  R Documentation 
Predicted risk, survival, hazard, or mortality from an ORSF model.
## S3 method for class 'orsf_fit'
predict(
object,
new_data,
pred_horizon = NULL,
pred_type = "risk",
na_action = "fail",
boundary_checks = TRUE,
...
)
object 
(orsf_fit) a trained oblique random survival forest (see orsf). 
new_data 
a data.frame, tibble, or data.table to compute predictions in. 
pred_horizon 
(double) a value or vector indicating the time(s)
that predictions will be calibrated to. E.g., if you were predicting
risk of incident heart failure within the next 10 years, then

pred_type 
(character) the type of predictions to compute. Valid options are

na_action 
(character) what should happen when

boundary_checks 
(logical) if 
... 
Further arguments passed to or from other methods (not currently used). 
new_data
must have the same columns with equivalent types as the data
used to train object
. Also, factors in new_data
must not have levels
that were not in the data used to train object
.
pred_horizon
values should not exceed the maximum followup time in
object
's training data, but if you truly want to do this, set
boundary_checks = FALSE
and you can use a pred_horizon
as large
as you want. Note that predictions beyond the maximum followup time
in the object
's training data are equal to predictions at the
maximum followup time, because aorsf
does not estimate survival
beyond its maximum observed time.
If unspecified, pred_horizon
may be automatically specified as the value
used for oobag_pred_horizon
when object
was created (see orsf).
a matrix
of predictions. Column j
of the matrix corresponds
to value j
in pred_horizon
. Row i
of the matrix corresponds to
row i
in new_data
.
Begin by fitting an ORSF ensemble:
library(aorsf) set.seed(329730) index_train < sample(nrow(pbc_orsf), 150) pbc_orsf_train < pbc_orsf[index_train, ] pbc_orsf_test < pbc_orsf[index_train, ] fit < orsf(data = pbc_orsf_train, formula = Surv(time, status) ~ .  id, oobag_pred_horizon = 365.25 * 5)
Predict risk, survival, or cumulative hazard at one or several times:
# predicted risk, the default predict(fit, new_data = pbc_orsf_test[1:5, ], pred_type = 'risk', pred_horizon = c(500, 1000, 1500))
## [,1] [,2] [,3] ## [1,] 0.502277249 0.78369254 0.92143996 ## [2,] 0.035699097 0.07776627 0.14863153 ## [3,] 0.110355739 0.26854128 0.40820574 ## [4,] 0.011659607 0.02787088 0.07267587 ## [5,] 0.006580104 0.01585194 0.04896800
# predicted survival, i.e., 1  risk predict(fit, new_data = pbc_orsf_test[1:5, ], pred_type = 'surv', pred_horizon = c(500, 1000, 1500))
## [,1] [,2] [,3] ## [1,] 0.4977228 0.2163075 0.07856004 ## [2,] 0.9643009 0.9222337 0.85136847 ## [3,] 0.8896443 0.7314587 0.59179426 ## [4,] 0.9883404 0.9721291 0.92732413 ## [5,] 0.9934199 0.9841481 0.95103200
# predicted cumulative hazard function # (expected number of events for person i at time j) predict(fit, new_data = pbc_orsf_test[1:5, ], pred_type = 'chf', pred_horizon = c(500, 1000, 1500))
## [,1] [,2] [,3] ## [1,] 0.705240501 1.37551172 1.79408459 ## [2,] 0.037859536 0.09860152 0.20087409 ## [3,] 0.131539617 0.38704960 0.68840843 ## [4,] 0.011659607 0.02870233 0.08408614 ## [5,] 0.006580104 0.01783446 0.05794846
Predict mortality, defined as the number of events in the forestâ€™s population if all observations had characteristics like the current observation. This type of prediction does not require you to specify a prediction horizon
predict(fit, new_data = pbc_orsf_test[1:5, ], pred_type = 'mort')
## [,1] ## [1,] 71.355153 ## [2,] 10.811443 ## [3,] 27.509084 ## [4,] 5.930542 ## [5,] 3.881523