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

## Usage

```
# S3 method for 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).

## 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`

.

## 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).

## 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.48792661 0.75620281 0.90618133
## [2,] 0.04293829 0.09112952 0.18602887
## [3,] 0.12147573 0.27784498 0.41600114
## [4,] 0.01136075 0.03401092 0.08236831
## [5,] 0.01294947 0.02070625 0.05645823
```

```
# 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.5120734 0.2437972 0.09381867
## [2,] 0.9570617 0.9088705 0.81397113
## [3,] 0.8785243 0.7221550 0.58399886
## [4,] 0.9886393 0.9659891 0.91763169
## [5,] 0.9870505 0.9792937 0.94354177
```

```
# 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.68107429 1.28607479 1.70338193
## [2,] 0.04519460 0.10911618 0.24871482
## [3,] 0.14686474 0.41252079 0.69005048
## [4,] 0.01149952 0.03951923 0.10628942
## [5,] 0.01338978 0.02214232 0.06644605
```

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,] 68.394152
## [2,] 12.299344
## [3,] 28.208251
## [4,] 6.475339
## [5,] 4.247305
```