Learn R Programming

ggRandomForests (version 4.0.0)

gg_rhf: Tidy hazard and cumulative-hazard curves from a Random Hazard Forest

Description

Extracts case-specific ensemble hazard and cumulative-hazard estimates from a fitted randomForestRHF::rhf() object into a tidy long data frame, one row per (case, time) pair on the forest's time.interest grid.

Usage

gg_rhf(object, ...)

# S3 method for rhf gg_rhf(object, source = c("oob", "inbag"), ...)

Value

A data.frame of class c("gg_rhf", "data.frame") with columns id, time, hazard, chf, source, an integer ntime attribute (number of grid points), and a provenance attribute.

The frame always has ntime rows per case. Both hazard and chf may be NA, and they are masked on different rules. From randomForestRHF

2.0.0 the pointwise hazard is defined only where a grid point falls inside one of the case's supplied (start, stop] intervals, and is NA in gaps and after the final stop time. From 2.0.3 the cumulative hazard is NA

after each case's final stop. randomForestRHF documents it as flat through an internal gap, but 2.1.0 returns NA from the start of a case's first gap to the end of its follow-up, including the observed interval after the gap, where the hazard is defined. So do not rely on chf for a case with a gap in its path. On a fit whose cases each have a single interval the two masks look the same; with time-dependent covariates they need not. Earlier versions carried chf across the whole grid. The values are passed through unchanged; use na.rm = TRUE when summarising either column, or see plot.gg_rhf(), which drops the masked cells before drawing.

Arguments

object

A fitted rhf object from randomForestRHF.

...

Not currently used.

source

Which ensemble estimate to extract: "oob" (default, out-of-bag) or "inbag". Falls back to the other when the requested one is absent (e.g. bootstrap = "none" has no OOB estimate).

References

Ishwaran H, Hsich EM, Kogalur UB, Lee DKK (2026). Random Hazard Forests. arXiv:2608.21597. tools:::Rd_expr_doi("10.48550/arXiv.2608.21597").

Ishwaran H, Kogalur UB (2026). randomForestRHF: Random Hazard Forests. R package version 2.0.3. https://CRAN.R-project.org/package=randomForestRHF.

See Also

plot.gg_rhf(), randomForestRHF::rhf()

Examples

Run this code
# \donttest{
if (requireNamespace("randomForestRHF", quietly = TRUE)) {
  data(pbc, package = "randomForestSRC")
  d <- randomForestRHF::convert.counting(
    survival::Surv(days, status) ~ ., na.omit(pbc))
  o <- randomForestRHF::rhf("Surv(id, start, stop, event) ~ .", d, ntree = 30)
  gg <- gg_rhf(o)
  plot(gg, idx = c(1, 5, 10))
}
# }

Run the code above in your browser using DataLab