plot.rhf.RdPlot case specific hazard and cumulative hazard (CHF) from a fitted
random hazard forest (RHF) object. Hazards are smoothed with
stats::supsmu. Optional scaling places hazards on the same
scale as the CHF for easier comparison.
# S3 method for class 'rhf'
plot(x, idx = NULL, scale.hazard = FALSE,
ngrid = 30, bass = 0, q = 0.99, grid = FALSE,
col = NULL, lty = NULL, legend.loc = "topright",
jitter.factor = 1, lwd = 4,
hazard.only = TRUE, legend.show = TRUE, ...)An rhf fit object returned by rhf.
Subject identifiers selecting which cases to plot. Values must
match those in unique(x$id); by default the first value is used.
Logical or numeric. If TRUE, hazards are
multiplied by the local time step so they approximate CHF increments.
If numeric, hazards are multiplied by the given constant.
Number of equally spaced points used when grid = TRUE.
Smoothing parameter passed to stats::supsmu.
Quantile used to trim extreme hazard values before smoothing.
If TRUE, overlays smoothed CHF and its derivative.
Colors for selected cases. Recycled as needed.
Line types for hazard and CHF curves.
Legend location. Passed to legend.
Amount of horizontal jitter applied to hazard spikes.
Line width for hazard spikes.
If TRUE, only the hazard is drawn.
If TRUE, show a legend when plotting multiple cases.
Additional graphics parameters passed to plot.
The function displays out of bag hazard and CHF estimates on the grid
x$time.interest. Hazards are smoothed using
supsmu after trimming large values for stability.
Scaling the hazard allows direct visual comparison with CHF.
Plots are drawn to the current device; no model re-estimation is
performed.
Invisibly returns NULL. The function is used for its plotting side effects.
Ishwaran H. and Kogalur U.B. (2007). Random survival forests for R. R News, 7(2): 25–31.
Ishwaran H., Kogalur U.B., Blackstone E.H. and Lauer M.S. (2008). Random survival forests. Annals of Applied Statistics, 2: 841–860.
Lee D.K., Chen N., and Ishwaran H. (2021). Boosted nonparametric hazards with time dependent covariates. Annals of Statistics, 49: 2101–2128.
Ishwaran H., Lee D.K. and Hsich E.M. (2025). Random hazard forests.
# \donttest{
## ------------------------------------------------------------
## time static peakVO2
## ------------------------------------------------------------
data(peakVO2, package = "randomForestSRC")
d <- convert.counting(Surv(ttodead, died)~., peakVO2)
f <- "Surv(id, start, stop, event) ~ ."
set.seed(1)
o <- rhf(f, d)
oldpar <- par(mfrow=c(1,1))
## plot selected cases
ids <- o$ensemble.id[1:3]
plot(o, idx = ids)
## hazard only
plot(o, idx = ids)
## scaled hazard with CHF
plot(o, idx = ids, scale.hazard = TRUE, hazard.only = FALSE)
## auxiliary grid with smoother control
plot(o, idx = ids, grid = TRUE, ngrid = 60, bass = 2, hazard.only = FALSE)
## multiple cases, no legend
plot(o, idx = o$ensemble.id[1:10], lwd = 0, legend.show = FALSE)
## lowess median smoothed hazard
s <- smoothed.hazard(o) ## default method="median.loess"
plot(s, idx = o$ensemble.id[1:10])
plot(s, idx = o$ensemble.id[1:10], lwd = 0)
par(oldpar)
## ------------------------------------------------------------
## complex simulated time dependent covariate hazards
## ------------------------------------------------------------
f <- "Surv(id, start, stop, event) ~ ."
sim2 <- hazard.simulation(2)$dta
o2 <- rhf(f, sim2)
oldpar <- par(mfrow=c(1,1))
plot(o2, 1)
par(oldpar)
## ------------------------------------------------------------
## same complex simulation, but using smoothed hazard
## ------------------------------------------------------------
f <- "Surv(id, start, stop, event) ~ ."
sim2 <- hazard.simulation(2)$dta
o2 <- rhf(f, sim2)
s2.loess <- smoothed.hazard(o2, method="loess")
s2.med.loess <- smoothed.hazard(o2, method="median.loess")
oldpar <- par(mfrow=c(1,1))
plot(o2, 1)
plot(s2.loess, 1)
plot(s2.med.loess, 1)
plot(s2.med.loess, 1:10, lwd = 0)
par(oldpar)
# }