predict.rhf: Prediction on Test Data for Random Hazard Forests

View source: R/predict.rhf.R

predict.rhfR Documentation

Prediction on Test Data for Random Hazard Forests

Description

Obtain predicted values on test data using a trained random hazard forests.

Usage

## S3 method for class 'rhf'
predict(object, newdata,  get.tree = NULL,
     block.size = 10, membership = TRUE, seed = NULL, do.trace = FALSE,...)

Arguments

object

An rhf object returned from a previous training call to rhf.

newdata

Test data frame. If omitted, the original training data is used and the full training forest is restored.

get.tree

Optional vector of integer indices specifying which trees to use for ensemble predictions. Defaults to using all trees in the forest.

block.size

Controls how cumulative error rate is reported. To obtain cumulative error every n trees, set this to an integer between 1 and ntree.

membership

Logical flag indicating whether terminal node membership and inbag information should be returned.

seed

Negative integer specifying the random seed for reproducibility.

do.trace

Number of seconds between progress updates printed to the console.

...

Additional optional arguments passed to internal methods.

Details

Returns the predicted values for a random hazard forests.

Value

An object of class c("rhf", "predict", family). The returned list contains the fitted forest together with prediction summaries on the evaluation grid time.interest. Important components include:

  • hazard.test, chf.test, risk.test, and int.haz.test: test-set hazard, cumulative hazard, risk, and integrated-hazard summaries when newdata is supplied.

  • hazard.oob, chf.oob, risk.oob, and int.haz.oob: out-of-bag summaries for the training data.

  • hazard.inbag, chf.inbag, risk.inbag, and int.haz.inbag: in-bag summaries when available.

  • id, yvar, and xvar: identifiers and processed outcome/predictor data used by the returned prediction object.

  • pseudo.membership and inbag: terminal-node membership and inbag information when membership = TRUE.

  • forest: the fitted forest object used to generate the predictions.

If newdata is omitted, the function restores predictions for the original training data using the stored forest and returns the same class of object.

Author(s)

Hemant Ishwaran and Udaya B. Kogalur

References

Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R, Rnews, 7(2):25-31.

Ishwaran H., Kogalur U.B., Blackstone E.H. and Lauer M.S. (2008). Random survival forests, Ann. App. Statist., 2:841-860.

Lee, D.K. and Chen N. and Ishwaran H (2021). Boosted nonparametric hazards with time-dependent covariates. Annals of Statistics, 49: 2101-2128.

See Also

rhf

Examples


## ------------------------------------------------------------
## canonical train/test example (synthetic data)
## ------------------------------------------------------------

simID <- 1
trn <- hazard.simulation(simID)$dta
tst <- hazard.simulation(simID)$dta
f <- "Surv(id, start, stop, event) ~ ."

## training
o <- rhf(f, trn, ntree = 3)
print(o)

## testing
p <- predict(o, tst)
print(p)



## ------------------------------------------------------------
##  pbc: train/test example
## ------------------------------------------------------------

library("randomForestSRC")
data(pbc, package = "randomForestSRC")
pbc.raw <- na.omit(pbc)
trn <- sample(1:nrow(pbc.raw), size=nrow(pbc.raw) * .75, replace = FALSE)

d.trn <- convert.counting(Surv(days, status) ~ ., pbc.raw[trn,])
d.tst <- convert.counting(Surv(days, status) ~ ., pbc.raw[-trn,])
f <- "Surv(id, start, stop, event) ~ ."

## train/predict
o <- rhf(f, d.trn)
print(predict(o, d.tst))

## restore the forest
print(predict(o))



randomForestRHF documentation built on April 24, 2026, 1:07 a.m.