Skip to contents

Final Production Wrapper for RFSRC (Tunable & Robust). Estimates a survival random forest using rfsrc.

Usage

surv.rfsrc(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  ntree = 1000,
  nodesize = 15,
  mtry = NULL,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data.frame.

newdata

Test covariate data.frame to use for prediction.

new.times

Times at which to obtain the predicted survivals.

obsWeights

Observation weights.

id

Currently ignored.

ntree

Number of trees to grow (default: 1000).

nodesize

Minimum number of deaths in terminal nodes (default: 15).

mtry

Number of variables randomly selected as candidates for splitting a node.

...

Additional arguments passed to rfsrc.

Value

A list containing:

  • fit: The fitted model object (e.g., the raw coxph or xgb.Booster object). If the model fails to fit, this may be an object of class try-error.

  • pred: A numeric matrix of cross-validated survival predictions evaluated at the specified new.times grid.

Examples

if (requireNamespace("randomForestSRC", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:30, ]
  x_cols <- grep("^x", names(dat))[1:3]
  X <- dat[, x_cols, drop = FALSE]
  newX <- X[1:5, , drop = FALSE]
  times <- seq(50, 150, by = 50)

  fit <- surv.rfsrc(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    ntree = 10,
    nodesize = 3
  )

  dim(fit$pred)
}
#> [1] 5 3