predict.rhf.RdObtain predicted values on test data using a trained random hazard forest, or restore predictions for its original training data.
# S3 method for class 'rhf'
predict(object, newdata, get.tree = NULL,
block.size = 10, membership = TRUE, adaptive = TRUE,
seed = NULL, do.trace = FALSE,...)An rhf object returned from a previous training
call to rhf.
Test data frame. For a forest grown from ordinary
Surv(time, event) input, newdata may be supplied in
the same ordinary survival format using the original time and event
column names. For a forest grown from counting-process input,
newdata uses Surv(id, start, stop, event) columns as
in the training data. If omitted, the original training data are
used and the full training forest is restored.
Optional vector of integer indices specifying which trees to use for ensemble predictions. Defaults to using all trees in the forest. Currently ignored, future functionality.
Controls how cumulative error rate is reported. To
obtain cumulative error every n trees, set this to an integer
between 1 and ntree. Currently ignored.
Logical flag indicating whether terminal node membership and inbag information should be returned.
Logical flag controlling the default trimmed-mean
protocol used by prediction and restore mode. The default
TRUE inherits the adaptive trim configuration saved with the
trained forest. Setting adaptive = FALSE replaces the default
or inherited trim grid by the fixed value 0.05, unless an
expert-level coe.trim value is supplied through ....
Negative integer specifying the random seed for reproducibility.
Number of seconds between progress updates printed to the console.
Additional optional arguments passed to internal methods.
For a forest grown directly from Surv(time, event) data,
predict.rhf() retains the original response names from the
training call. When both response columns are present in
newdata, each test row is converted internally to one interval
with start = 0, stop = time, and the supplied event
indicator. This gives the same test-data representation that would
have been obtained by calling convert.counting() explicitly.
The time and event columns must be either both present or both absent.
When both are absent, prediction can still return terminal membership
and training-derived node summaries, but case-specific test hazard and
cumulative-hazard trajectories are not assembled because no test
follow-up interval has been supplied.
Forests grown from Surv(id, start, stop, event) data retain the
existing counting-process prediction interface. In either format,
predictor names must match those used to grow the forest.
Prediction inherits the hazard calculation configuration saved with
the trained forest. In ordinary test-data prediction there is no OOB
objective for reselecting the trim value, so the grow-time selected
index is used. In restore mode, the stored forest can reconstruct OOB
quantities and may reselect the trim value over the active candidate
grid. Setting adaptive = FALSE changes that grid to the single
value 0.05, unless coe.trim is supplied through
....
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.
event.process and input.info: the trained event-process
classification and the original survival-input format and response map.
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.
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.
Ishwaran H. (2025). Multivariate Statistics: Classical Foundations and Modern Machine Learning. Chapman and Hall.
Ishwaran H., Kogalur U.B., Hsich E.M. and Lee D.K. (2026). Random hazard forests.
## ------------------------------------------------------------
## 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)
## fixed trim protocol
p.fixed <- predict(o, tst, adaptive = FALSE)
# \donttest{
## ------------------------------------------------------------
## pbc: train/test example
## ------------------------------------------------------------
library("randomForestSRC")
data(pbc, package = "randomForestSRC")
pbc.raw <- na.omit(pbc)
set.seed(7)
trn <- sample(
seq_len(nrow(pbc.raw)),
size = floor(nrow(pbc.raw) * .75),
replace = FALSE
)
pbc.trn <- pbc.raw[trn, , drop = FALSE]
pbc.tst <- pbc.raw[-trn, , drop = FALSE]
f <- Surv(days, status) ~ .
## train and predict directly with ordinary right-censored data
o <- rhf(f, pbc.trn)
print(predict(o, pbc.tst))
## restore the training forest
print(predict(o))
# }