predict.orsf_fit {aorsf} R Documentation

## Compute predictions using ORSF

### Description

Predicted risk, survival, hazard, or mortality from an ORSF model.

### Usage

## S3 method for class 'orsf_fit'
predict(
object,
new_data,
pred_horizon = NULL,
pred_type = "risk",
na_action = "fail",
boundary_checks = TRUE,
...
)


### Arguments

 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_horizon = 10. pred_horizon can be NULL if pred_type is 'mort', since mortality predictions are aggregated over all event times pred_type (character) the type of predictions to compute. Valid options are 'risk' : probability of having an event at or before pred_horizon. 'surv' : 1 - risk. 'chf': cumulative hazard function 'mort': mortality prediction na_action (character) what should happen when new_data contains missing values (i.e., NA values). Valid options are: 'fail' : an error is thrown if new_data contains NA values 'pass' : the output will have NA in all rows where new_data has 1 or more NA value for the predictors used by object 'omit' : rows in new_data with incomplete data will be dropped 'impute_meanmode' : missing values for continuous and categorical variables in new_data will be imputed using the mean and mode, respectively. To clarify, the mean and mode used to impute missing values are from the training data of object, not from new_data. boundary_checks (logical) if TRUE, pred_horizon will be checked to make sure the requested values are less than the maximum observed time in object's training data. If FALSE, these checks are skipped. ... Further arguments passed to or from other methods (not currently used).

### Details

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 follow-up 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 follow-up time in the object's training data are equal to predictions at the maximum follow-up 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).

### Value

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.

### Examples

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


[Package aorsf version 0.0.4 Index]