Nonparametric survival estimates.
Usage
gg_survival(
object = NULL,
interval = NULL,
censor = NULL,
by = NULL,
data = NULL,
type = c("kaplan", "nelson"),
...
)
# S3 method for class 'rfsrc'
gg_survival(
object,
interval = NULL,
censor = NULL,
by = NULL,
data = NULL,
type = c("kaplan", "nelson"),
...
)
# Default S3 method
gg_survival(
object = NULL,
interval = NULL,
censor = NULL,
by = NULL,
data = NULL,
type = c("kaplan", "nelson"),
...
)Arguments
- object
For the
rfsrcmethod: a fittedrfsrcsurvival forest. For the default method: passNULL(or omit) and supplyinterval,censor, anddatainstead.- interval
Character; name of the time-to-event column in
data(default method only).- censor
Character; name of the event-indicator column in
data(1 = event, 0 = censored; default method only).- by
Optional character; name of a grouping column for stratified estimates. For the
rfsrcmethod,bymust be a column inobject$xvar.- data
A
data.framecontaining survival data (default method only).- type
One of
"kaplan"(Kaplan-Meier, default) or"nelson"(Nelson-Aalen cumulative hazard). Default method only.- ...
Value
A gg_survival data.frame with columns time,
surv, cum_haz, lower, upper, n.risk,
and optionally groups when by is supplied.
Details
Comparing the forest's ensemble survival curve to the marginal
Kaplan-Meier baseline is a quick sanity check: if they diverge the forest
has found structure the predictors carry; if they track each other closely
the predictors may add little. gg_survival computes
the nonparametric baseline – the Kaplan-Meier or Nelson-Aalen estimate –
so you can place it on the same canvas as the forest predictions from
gg_rfsrc.
gg_survival is an S3 generic that dispatches on the class of its
first argument:
rfsrcExtracts the outcome columns from the fitted forest's
$yvarslot (time in column 1, event indicator in column 2) and delegates tokaplan. Usebyto stratify on a predictor from$xvar: you get one Kaplan-Meier curve per group, ready to compare against the forest's group-specific ensemble curves.- default
Accepts raw survival columns directly via
interval,censor, anddata. Delegates tokaplan(the default) ornelsondepending ontype.
Note
Survival estimation is randomForestSRC-only; randomForest
has no survival forest, so no randomForest method exists.
Examples
## -------- pbc data (default method, raw data columns)
data(pbc, package = "randomForestSRC")
pbc$time <- pbc$days / 364.25
gg_dta <- gg_survival(interval = "time", censor = "status", data = pbc)
plot(gg_dta, error = "none")
# Stratified
gg_dta <- gg_survival(
interval = "time", censor = "status",
data = pbc, by = "treatment"
)
plot(gg_dta)