Package {SuperSurv}


Type: Package
Title: A Unified Framework for Machine Learning Ensembles in Survival Analysis
Version: 0.1.9
Author: Yue Lyu [aut, cre]
Maintainer: Yue Lyu <yuelyu0521@gmail.com>
Description: Implements a Super Learner framework for right-censored survival data. The package fits convex combinations of parametric, semiparametric, and machine learning survival learners by minimizing cross-validated risk using inverse probability of censoring weighting (IPCW). It provides tools for automated hyperparameter grid search, high-dimensional variable screening, and evaluation of prediction performance using metrics such as the Brier score, Uno's C-index, and time-dependent area under the curve (AUC). Additional utilities support model interpretation for survival ensembles, including Shapley additive explanations (SHAP), and estimation of covariate-adjusted restricted mean survival time (RMST) contrasts. The methodology is related to treatment-specific survival curve estimation using machine learning described by Westling et al. (2024) <doi:10.1080/01621459.2023.2205060>, and the unified ensemble framework described in Lyu et al. (2026) <doi:10.64898/2026.03.11.711010>.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.0
Depends: R (≥ 4.0.0)
LazyData: true
Imports: survival, nnls, future.apply, stats, utils, dplyr, magrittr
URL: https://github.com/yuelyu21/SuperSurv, https://yuelyu21.github.io/SuperSurv/
BugReports: https://github.com/yuelyu21/SuperSurv/issues
Suggests: aorsf, BART, CoxBoost, flexsurv, glmnet, gbm, grf, mgcv, mboost, randomForestSRC, ranger, reticulate, riskRegression, rpart, survivalmodels, survPen, survivalsvm, xgboost, kernelshap, survex, ggplot2, tidyr, quadprog, ggforce, patchwork, knitr, rmarkdown
VignetteBuilder: knitr, rmarkdown
NeedsCompilation: no
Packaged: 2026-10-02 04:20:32 UTC; a98455
Repository: CRAN
Date/Publication: 2026-10-02 13:50:02 UTC

Super Learner for conditional survival functions

Description

Orchestrates the cross-validation, metalearner optimization, and prediction for an ensemble of survival base learners.

Usage

SuperSurv(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  event.library,
  cens.library,
  id = NULL,
  verbose = FALSE,
  control = list(),
  cvControl = list(),
  obsWeights = NULL,
  metalearner = "brier",
  selection = "ensemble",
  nFolds = 10,
  parallel = FALSE
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data.frame.

newdata

Test covariate data.frame for prediction (defaults to X).

new.times

Times at which to obtain predicted survivals.

event.library

Character vector of prediction algorithms for the event.

cens.library

Character vector of prediction algorithms for censoring.

id

Cluster identification variable.

verbose

Logical. If TRUE, prints progress messages.

control

List of control parameters for the Super Learner.

cvControl

List of control parameters for cross-validation.

obsWeights

Observation weights.

metalearner

Character string specifying the optimizer. Supported choices are "brier" and "logloss". The legacy "entropy" option is deprecated and retained temporarily for backward compatibility.

selection

Character. Specifies how the meta-learner combines the base models. Use "ensemble" (default) to calculate a weighted average (convex combination) of the base learners. Use "best" to act as a Discrete Super Learner, which assigns a weight of 1.0 to the single model with the lowest cross-validated risk.

nFolds

Number of cross-validation folds (default: 10).

parallel

Logical. If TRUE, uses future.apply for parallel execution.

Details

Extending the learner library. Custom base learners can be added by defining a wrapper function and passing its name in event.library or cens.library. A learner wrapper should accept time, event, X, newdata, new.times, obsWeights, id, and ..., and should return a list with pred, a numeric survival-probability matrix with nrow(newdata) rows and length(new.times) columns, and fit, the fitted object used for future prediction. If saved fits are needed, give fit a class and provide a corresponding predict.<class>() method that returns the same matrix shape. Wrapper outputs are validated before they enter the ensemble. Malformed prediction dimensions, non-finite values, values outside [0, 1], or a missing saved fit produce an error naming the learner and fitting stage.

Screening methods can also be supplied by name. A screener should accept the training inputs and return a logical vector aligned with the columns of X. Learner and screener names are resolved in the calling environment first, with package functions as a fallback. The resolved functions are reused across folds and full-data fitting, including parallel cross-validation. Thus, locally defined wrappers and grids can be used without assigning them globally. Prediction methods for custom fitted-object classes must still be available through normal S3 dispatch when predicting from saved fits. See vignette("extending-supersurv", package = "SuperSurv") for a practical custom learner and screener example.

Value

A list of class SuperSurv containing:

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  fit
  event_weights(fit)
}

Control parameters for Cross-Validation in SuperSurv

Description

Control parameters for Cross-Validation in SuperSurv

Usage

SuperSurv.CV.control(
  V = 10L,
  stratifyCV = TRUE,
  shuffle = TRUE,
  validRows = NULL
)

Arguments

V

Number of folds. Default is 10.

stratifyCV

Logical. If TRUE, ensures event rates are balanced across folds.

shuffle

Logical. If TRUE, shuffles rows before splitting.

validRows

Optional custom list of indices for folds.

Value

A list of CV parameters.


Control parameters for the SuperSurv Ensemble

Description

Control parameters for the SuperSurv Ensemble

Usage

SuperSurv.control(
  max.SL.iter = 20,
  event.t.grid = NULL,
  cens.t.grid = NULL,
  saveFitLibrary = TRUE,
  initWeightAlg = "surv.coxph",
  initWeight = "censoring",
  tol = 1e-05,
  traceIter = FALSE,
  ipcw.floor = 1e-04,
  ipcw.cap = 100,
  logloss.eps = 1e-10,
  optimizer.tol = 1e-08,
  optimizer.maxit = 10000L,
  truncation.warn.fraction = 0.05
)

Arguments

max.SL.iter

Maximum iterations for the iterative weighting algorithm. Default 20.

event.t.grid

Optional time grid for event risk calculation.

cens.t.grid

Optional time grid for censoring risk calculation.

saveFitLibrary

Logical. If TRUE (default), saves models for future predictions.

initWeightAlg

The learner used for the very first step of IPCW.

initWeight

Whether to start by fitting "censoring" or "event" weights.

tol

Positive convergence tolerance for the maximum change in the out-of-fold event and censoring ensemble predictions.

traceIter

Logical. If TRUE, reports iteration diagnostics.

ipcw.floor

Smallest censoring or event survival probability used in an IPCW denominator.

ipcw.cap

Largest inverse-probability weight used in an IPCW loss.

logloss.eps

Probability clipping constant used only while evaluating logarithms in the IPCW log-loss.

optimizer.tol

Positive convergence tolerance for metalearner optimization.

optimizer.maxit

Maximum number of metalearner optimization iterations.

truncation.warn.fraction

Fraction of IPCW rows stabilized by flooring or truncation above which a warning is issued.

Value

A list of control parameters.


Extract SuperSurv ensemble coefficients

Description

Returns the optimized convex-combination weights from a fitted SuperSurv object.

Usage

## S3 method for class 'SuperSurv'
coef(object, type = c("event", "censoring", "both"), ...)

Arguments

object

A fitted object of class "SuperSurv".

type

Character string specifying which weights to return. Use "event" for the event-time ensemble, "censoring" for the censoring ensemble, or "both" for both sets of weights.

...

Additional arguments ignored.

Value

For type = "event" or type = "censoring", a named numeric vector of ensemble weights. For type = "both", a list with elements event and censoring.

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  coef(fit)
  coef(fit, type = "both")
}

Create a Tuning Grid of Survival Learners

Description

Dynamically generates custom wrapper functions for a specified base learner across a grid of hyperparameters.

Usage

create_grid(base_learner, grid_params)

Arguments

base_learner

Character string of the base learner function name (e.g., "surv.gbm").

grid_params

List of numeric/character vectors containing hyperparameter values.

Details

Generated functions are assigned to the calling environment. The base learner is resolved there (with package functions as a fallback) when the grid is created and retained by each generated function. Local base learners and grids can therefore be used inside a function that calls SuperSurv(), without modifying the global environment.

Value

A character vector of class "SuperSurv_grid" containing the newly generated function names.


Estimate an Adjusted Marginal RMST Contrast

Description

Computes a covariate-adjusted marginal contrast on the restricted mean survival time (RMST) scale using standardization (g-computation) based on a fitted SuperSurv model.

Usage

estimate_marginal_rmst(
  fit,
  data,
  trt_col,
  times,
  tau,
  inference = FALSE,
  B = 200,
  seed = NULL,
  ci_level = 0.95
)

Arguments

fit

A fitted object of class "SuperSurv".

data

A data.frame containing the covariates used for standardization, including the binary grouping variable specified by trt_col.

trt_col

Character string giving the name of the binary grouping variable in data. The variable is set to 1 and 0, respectively, to generate the two standardized prediction regimes.

times

Numeric vector of prediction time points corresponding to the evaluation grid used for survival prediction.

tau

Numeric scalar giving the restriction horizon for RMST. Must not exceed max(times).

inference

Deprecated compatibility argument. Formal inference is not provided; it requires a validated procedure accounting for model-estimation uncertainty. Must remain FALSE.

B, seed, ci_level

Deprecated compatibility arguments; ignored when inference = FALSE.

Details

For a binary grouping variable trt_col, the function predicts counterfactual survival curves under A = 1 and A = 0 for every individual in the supplied dataset, integrates each curve up to the restriction time tau, and averages the resulting individual-level RMST differences. The resulting contrast is generally interpreted as an adjusted marginal contrast. When trt_col corresponds to a manipulable intervention and additional identification assumptions hold, the same standardized procedure may also support a causal interpretation.

The function uses the empirical distribution of the observed covariates in data as the standardization distribution. RMST is evaluated numerically from the predicted survival matrix using a left Riemann sum over the supplied grid times.

The returned contrast is a model-based point estimate. Formal uncertainty quantification would need to account for nuisance estimation, tuning, cross-validation, learner fitting, and ensemble-weight estimation, for example through a validated full-pipeline refitting procedure.

Value

A list containing:

Examples

## Not run: 
data("metabric", package = "SuperSurv")
x_cols <- grep("^x", names(metabric), value = TRUE)
X <- metabric[, x_cols]
new.times <- seq(10, 150, by = 10)

fit <- SuperSurv(
  time = metabric$duration,
  event = metabric$event,
  X = X,
  newdata = X,
  new.times = new.times,
  event.library = c("surv.coxph", "surv.rfsrc"),
  cens.library = c("surv.coxph"),
  control = list(saveFitLibrary = TRUE),
  nFolds = 3
)

rmst_res <- estimate_marginal_rmst(
  fit = fit,
  data = metabric,
  trt_col = "x4",
  times = new.times,
  tau = 100
)

rmst_res$ATE_RMST

## End(Not run)


Evaluate survival predictions across models and times

Description

Computes a common set of numerical benchmark results for a fitted SuperSurv object or supported standalone learner. The censoring distribution used by the Brier score and time-dependent AUC is estimated marginally by Kaplan-Meier. For conditional censoring models, resampling, inference, or formal model comparisons, use a specialist evaluator such as riskRegression::Score().

Usage

eval_benchmark(
  object,
  newdata,
  time,
  event,
  eval_times,
  risk_time = stats::median(eval_times),
  verbose = FALSE
)

Arguments

object

A fitted SuperSurv object.

newdata

A data.frame of test covariates.

time

Numeric vector of observed follow-up times for the test set.

event

Numeric vector of event indicators for the test set.

eval_times

Numeric vector of times at which to evaluate survival predictions.

risk_time

Numeric. The specific time horizon used when extracting risk scores for Uno C-index. Defaults to the median of eval_times.

verbose

Logical; if TRUE, progress messages are shown.

Value

A list of class "SuperSurv_benchmark" containing summary, a model-level table; by_time, a time-specific table; and the prediction grid and risk horizon.


IPCW Brier Score and Integrated Brier Score (IBS)

Description

Calculates the Inverse Probability of Censoring Weighted (IPCW) Brier Score over a grid of times, and computes the Integrated Brier Score (IBS) using trapezoidal integration.

Usage

eval_brier(
  time,
  event,
  S_mat,
  times,
  tmin = min(times),
  tmax = max(times),
  ipcw_floor = 1e-06
)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

S_mat

A numeric matrix of predicted survival probabilities (rows = observations, columns = time points).

times

Numeric vector of evaluation times matching the columns of S_mat.

tmin

Numeric. Lower bound for IBS integration. Defaults to min(times).

tmax

Numeric. Upper bound for IBS integration. Defaults to max(times).

ipcw_floor

Positive numeric lower bound applied to the marginal Kaplan-Meier estimate of the censoring survival function before inversion.

Value

A list containing:

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:40, ]
x_cols <- grep("^x", names(dat))[1:3]
X <- dat[, x_cols, drop = FALSE]
newX <- X[1:10, , drop = FALSE]
times <- seq(50, 150, by = 50)

fit <- surv.coxph(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

eval_brier(
  time = dat$duration[1:10],
  event = dat$event[1:10],
  S_mat = fit[["pred"]],
  times = times
)

Calculate Concordance Index (Harrell's or Uno's)

Description

Calculate Concordance Index (Harrell's or Uno's)

Usage

eval_cindex(time, event, S_mat, times, eval_time, method = "uno")

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

S_mat

A numeric matrix of predicted survival probabilities.

times

Numeric vector of evaluation times matching the columns of S_mat.

eval_time

Numeric. The specific time point at which to extract predictions.

method

Character. Either "harrell" or "uno". Defaults to "uno".

Value

A numeric value representing the chosen C-index.

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:40, ]
x_cols <- grep("^x", names(dat))[1:3]
X <- dat[, x_cols, drop = FALSE]
newX <- X[1:10, , drop = FALSE]
times <- seq(50, 150, by = 50)

fit <- surv.coxph(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

eval_cindex(
  time = dat$duration[1:10],
  event = dat$event[1:10],
  S_mat = fit[["pred"]],
  times = times,
  eval_time = 100,
  method = "uno"
)

IPCW Log-Loss and Integrated IPCW Log-Loss

Description

Evaluates the two-term inverse-probability-of-censoring weighted log-loss. By default, censoring survival is estimated using marginal reverse Kaplan-Meier. Conditional or externally estimated censoring survival values can instead be supplied explicitly. Probability clipping is applied only inside logarithms.

Usage

eval_logloss(
  time,
  event,
  S_mat,
  times,
  tmin = min(times),
  tmax = max(times),
  ipcw_floor = 1e-06,
  eps = 1e-10,
  ipcw_cap = Inf,
  G_T_left = NULL,
  G_times = NULL
)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

S_mat

A numeric matrix of predicted survival probabilities (rows = observations, columns = time points).

times

Numeric vector of evaluation times matching the columns of S_mat.

tmin

Numeric. Lower bound for IBS integration. Defaults to min(times).

tmax

Numeric. Upper bound for IBS integration. Defaults to max(times).

ipcw_floor

Positive lower bound applied to censoring survival before inversion.

eps

Probability clipping constant in (0, 0.5).

ipcw_cap

Largest IPCW contribution. Use Inf for no cap.

G_T_left

Optional numeric vector containing subject-specific G(T_i-\mid X_i) values. Supply together with G_times.

G_times

Optional numeric matrix with the dimensions of S_mat containing G(t\mid X_i), or a vector aligned with times for a common censoring survival curve. Supply together with G_T_left.

Value

A list containing logloss_scores, integrated_logloss, times, and diagnostics. Diagnostics report the effective denominator threshold, intervention counts, weight quantiles, effective sample sizes, and the fraction of weighted loss contributed by capped rows, separately for failure and survivor terms.


Evaluate SuperSurv predictions on test data

Description

Computes the integrated Brier score (IBS), Uno C-index, and integrated area under the curve (iAUC) for the SuperSurv ensemble and all individual base learners.

Usage

eval_summary(
  object,
  newdata,
  time,
  event,
  eval_times,
  risk_time = stats::median(eval_times),
  verbose = FALSE
)

Arguments

object

A fitted SuperSurv object.

newdata

A data.frame of test covariates.

time

Numeric vector of observed follow-up times for the test set.

event

Numeric vector of event indicators for the test set.

eval_times

Numeric vector of times at which to evaluate survival predictions.

risk_time

Numeric. The specific time horizon used when extracting risk scores for Uno C-index. Defaults to the median of eval_times.

verbose

Logical; if TRUE, progress messages are shown.

Value

A data frame of integrated benchmark metrics for the ensemble and base learners. Use eval_benchmark() to also obtain time-specific numerical results.

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:80, ]
x_cols <- grep("^x", names(dat))[1:3]

fit <- SuperSurv(
  time = dat$duration,
  event = dat$event,
  X = dat[, x_cols, drop = FALSE],
  new.times = seq(50, 200, by = 50),
  event.library = c("surv.coxph", "surv.km"),
  cens.library = c("surv.coxph", "surv.km")
)

res <- eval_summary(
  object = fit,
  newdata = dat[, x_cols, drop = FALSE],
  time = dat$duration,
  event = dat$event,
  eval_times = seq(50, 200, by = 50)
)

res


Time-Dependent AUC and Integrated AUC

Description

Evaluates the cumulative/dynamic time-dependent AUC and integrated AUC (iAUC) using inverse probability of censoring weighting (IPCW).

Usage

eval_timeROC(time, event, S_mat, times)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

S_mat

A numeric matrix of predicted survival probabilities.

times

Numeric vector of evaluation times matching the columns of S_mat.

Value

A list containing the AUC_curve at each time point, the times, and the integrated AUC iAUC.

Examples

 data("metabric", package = "SuperSurv")
 dat <- metabric[1:40, ]
 x_cols <- grep("^x", names(dat))[1:3]
 X <- dat[, x_cols, drop = FALSE]
 newX <- X[1:10, , drop = FALSE]
 times <- seq(50, 150, by = 50)

 fit <- surv.coxph(
   time = dat$duration,
   event = dat$event,
   X = X,
   newdata = newX,
   new.times = times,
   obsWeights = rep(1, nrow(dat)),
   id = NULL
 )

 eval_timeROC(
   time = dat$duration[1:10],
   event = dat$event[1:10],
   S_mat = fit[["pred"]],
   times = times
 )

Access SuperSurv prediction evaluation times

Description

Returns the time grid used for the fitted SuperSurv predictions.

Usage

eval_times(object, ...)

## Default S3 method:
eval_times(object, ...)

## S3 method for class 'SuperSurv'
eval_times(object, ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

Value

A numeric vector of prediction evaluation times.


Access SuperSurv ensemble weights

Description

Extracts the fitted event or censoring ensemble weights from a SuperSurv object.

Usage

event_weights(object, ...)

## Default S3 method:
event_weights(object, ...)

## S3 method for class 'SuperSurv'
event_weights(object, ...)

censor_weights(object, ...)

## Default S3 method:
censor_weights(object, ...)

## S3 method for class 'SuperSurv'
censor_weights(object, ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

Value

A named numeric vector of ensemble weights.

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  event_weights(fit)
  censor_weights(fit)
}

Explain Predictions with Global SHAP (Kernel SHAP)

Description

Explain Predictions with Global SHAP (Kernel SHAP)

Usage

explain_kernel(
  model,
  X_explain,
  X_background,
  nsim = 20,
  only_best = FALSE,
  verbose = FALSE,
  eval_time = NULL
)

Arguments

model

A fitted SuperSurv object OR a single wrapper output.

X_explain

The dataset you want to explain (e.g., X_test[1:10, ]).

X_background

Reference data defining the Kernel SHAP background distribution (for example, X_train[1:100, ]).

nsim

Positive integer controlling the approximate coalition-sampling budget. It is converted to an even m = 2 * nsim; small feature sets are evaluated exactly by kernelshap. Defaults to 20.

only_best

Logical. If TRUE and model is SuperSurv, only explains the highest-weighted base learner.

verbose

Logical; if TRUE, progress messages are shown.

eval_time

One finite, non-negative prediction time. Required explicitly so that all explanations target event probability 1 - S(eval_time).

Details

The explained function uses the stored survival-prediction methods, including screening and calibration. All positive ensemble weights are used; small weights are not discarded. This replaces the earlier mixture of native learner scores, so SHAP values from earlier releases are not comparable. The background sample defines marginal, not conditional or causal, SHAP values.

Value

A data.frame of class c("explain", "data.frame") containing the calculated SHAP values. The columns correspond to the covariates in X_explain. Attributes include baseline, predictions, eval_time, target = "event_probability", and backend convergence information.

Examples

if (FALSE) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  shap_values <- explain_kernel(
    model = fit,
    X_explain = X[1:10, , drop = FALSE],
    X_background = X[11:40, , drop = FALSE],
    nsim = 5, eval_time = 100
  )

  dim(shap_values)
}

Create a Time-Dependent Survex Explainer

Description

Bridges a fitted SuperSurv ensemble or a single base learner to the survex package for Time-Dependent SHAP and Model Parts.

Usage

explain_survex(model, data, y, times, label = NULL)

Arguments

model

A fitted SuperSurv object OR a single wrapper output.

data

Covariate data for explanation (data.frame).

y

The survival object (Surv(time, event)).

times

The time grid for evaluation.

label

Optional character string to name the explainer.

Value

An explainer object of class survex_explainer created by explain_survival, which can be passed to DALEX and survex functions for further model diagnostics and plotting.

Examples

if (requireNamespace("survex", quietly = TRUE) &&
    requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  times <- seq(20, 120, by = 20)
  y <- survival::Surv(dat$duration, dat$event)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  explainer <- explain_survex(
    model = fit,
    data = X,
    y = y,
    times = times,
    label = "SuperSurv_demo"
  )

  class(explainer)
}

Calculate Restricted Mean Survival Time (RMST)

Description

Calculate Restricted Mean Survival Time (RMST)

Usage

get_rmst(surv_matrix, times, tau)

Arguments

surv_matrix

Matrix of survival probabilities (rows: patients, cols: time points)

times

Vector of time points corresponding to the columns

tau

The restriction time horizon

Value

A vector of RMST values for each patient


Access SuperSurv learner names

Description

Returns the fitted learner names from a SuperSurv object.

Usage

learner_names(object, ...)

## Default S3 method:
learner_names(object, ...)

## S3 method for class 'SuperSurv'
learner_names(object, type = c("event", "censoring", "both"), ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

type

Character string specifying whether to return event learner names, censoring learner names, or both.

Value

For type = "event" or type = "censoring", a character vector of learner names. For type = "both", a list with elements event and censoring.


List Available Wrappers and Screeners in SuperSurv

Description

This function prints all built-in prediction algorithms and feature screening algorithms available in the SuperSurv package.

Usage

list_wrappers(what = "both")

Arguments

what

Character string. If "both" (default), lists both prediction and screening functions. If "surv", lists only prediction models. If "screen", lists only screening algorithms. Otherwise, lists all exports.

Value

An invisible character vector containing the requested function names.

Examples

list_wrappers()

METABRIC Breast Cancer Dataset

Description

A subset of the Molecular Taxonomy of Breast Cancer International Consortium (METABRIC) dataset to demonstrate the SuperSurv package. 9 Covariates: 4 gene indicators (MKI67, EGFR, PGR, and ERBB2) and 5 clinical features (age at diagnosis, and indicators for hormone treatment, radiotherapy, and chemotherapy)

Usage

metabric

Format

A data frame with the clinical and genomic variables:

duration

Survival time.

event

Event indicator (1 = event, 0 = censored).

x0

Feature x0.

x1

Feature x1.

x2

Feature x2.

x3

Feature x3.

x4

Feature x4.

x5

Feature x5.

x6

Feature x6.

x7

Feature x7.

x8

Feature x8.


Beeswarm Summary Plot for SuperSurv SHAP

Description

Beeswarm Summary Plot for SuperSurv SHAP

Usage

plot_beeswarm(shap_values, data, top_n = 10)

Arguments

shap_values

The output from explain_kernel().

data

The covariate data used (X_explain)

top_n

Number of features to display

Value

A ggplot object visualizing the SHAP values.

Examples

if (FALSE) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  shap_values <- explain_kernel(
    model = fit,
    X_explain = X[1:20, , drop = FALSE],
    X_background = X[21:50, , drop = FALSE],
    nsim = 5, eval_time = 100
  )

  plot_beeswarm(
    shap_values = shap_values,
    data = X[1:20, , drop = FALSE],
    top_n = 5
  )
}

Plot Longitudinal Benchmark Metrics

Description

Generates time-dependent performance curves comparing the SuperSurv ensemble against its base learners, or evaluates a single standalone learner.

Usage

plot_benchmark(
  object,
  newdata,
  time,
  event,
  eval_times,
  metrics = c("brier", "auc", "cindex"),
  verbose = FALSE
)

Arguments

object

A fitted SuperSurv object, a fitted standalone learner, or a benchmark returned by eval_benchmark(). A benchmark is plotted without recomputing predictions or metrics.

newdata

A data.frame of test covariates. Omit when object is a benchmark.

time

Numeric vector of observed follow-up times for the test set. Omit when object is a benchmark.

event

Numeric vector of event indicators for the test set. Omit when object is a benchmark.

eval_times

Numeric vector of times at which to evaluate predictions. Omit when object is a benchmark.

metrics

Character vector specifying which plots to return. Options: "brier", "auc", "cindex". Defaults to all three.

verbose

Logical; if TRUE, progress messages are shown. Defaults to FALSE.

Value

A combined patchwork object when patchwork is installed, a single ggplot when one metric is selected, or a named list of ggplots when multiple metrics are requested without patchwork.

Examples

if (requireNamespace("ranger", quietly = TRUE) &&
    requireNamespace("ggplot2", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:120, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  eval_times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = eval_times,
    event.library = c("surv.coxph", "surv.ranger"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  plot_benchmark(
    object = fit,
    newdata = X,
    time = dat$duration,
    event = dat$event,
    eval_times = eval_times,
    metrics = c("brier")
  )
}

Plot Survival Calibration Curve

Description

Plot Survival Calibration Curve

Usage

plot_calibration(object, newdata, time, event, eval_time, bins = 5)

Arguments

object

A fitted SuperSurv object OR a standalone base learner.

newdata

A data.frame of test covariates.

time

Numeric vector of observed follow-up times for the test set.

event

Numeric vector of event indicators for the test set.

eval_time

Numeric. A single time point at which to assess calibration.

bins

Integer. Defaults to 5.

Value

A ggplot object.

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:120, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  eval_times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = eval_times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  plot_calibration(
    object = fit,
    newdata = X,
    time = dat$duration,
    event = dat$event,
    eval_time = 100,
    bins = 4
  )
}

Plot SHAP Dependence for SuperSurv

Description

Plot SHAP Dependence for SuperSurv

Usage

plot_dependence(shap_values, data, feature_name, title = NULL)

Arguments

shap_values

The output from explain_kernel().

data

The original covariate data used for the explanation (X_explain)

feature_name

String name of the column to plot

title

Optional custom title.

Value

A ggplot object visualizing the SHAP values.

Examples

if (FALSE) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  shap_values <- explain_kernel(
    model = fit,
    X_explain = X[1:20, , drop = FALSE],
    X_background = X[21:50, , drop = FALSE],
    nsim = 5, eval_time = 100
  )

  plot_dependence(
    shap_values = shap_values,
    data = X[1:20, , drop = FALSE],
    feature_name = colnames(X)[1]
  )
}

Plot Global Feature Importance for SuperSurv

Description

Plot Global Feature Importance for SuperSurv

Usage

plot_global_importance(
  shap_values,
  title = "SuperSurv: Ensemble Feature Importance",
  top_n = 10
)

Arguments

shap_values

The output from explain_kernel().

title

Plot title.

top_n

Number of features to show (default 10)

Value

A ggplot object visualizing the SHAP values.

Examples

if (FALSE) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  shap_values <- explain_kernel(
    model = fit,
    X_explain = X[1:10, , drop = FALSE],
    X_background = X[11:40, , drop = FALSE],
    nsim = 5, eval_time = 100
  )

  plot_global_importance(shap_values, top_n = 5)
}

Plot Adjusted Marginal RMST Contrast Over Time

Description

Generates a curve showing how the adjusted marginal restricted mean survival time (RMST) contrast evolves across a sequence of restriction times.

Usage

plot_marginal_rmst_curve(
  fit,
  data,
  trt_col,
  times,
  tau_seq,
  inference = FALSE,
  B = 200,
  seed = NULL,
  ci_level = 0.95
)

Arguments

fit

A fitted SuperSurv ensemble object.

data

A data.frame containing the covariates and the binary grouping variable.

trt_col

Character string. The exact name of the binary grouping variable in data.

times

Numeric vector of time points matching the prediction grid.

tau_seq

Numeric vector. A sequence of restriction times (tau) to evaluate and plot.

inference

Deprecated compatibility argument. Must remain FALSE.

B, seed, ci_level

Deprecated compatibility arguments; ignored.

Value

A ggplot object visualizing the adjusted marginal RMST contrast curve.

Examples

if (requireNamespace("ggplot2", quietly = TRUE)) {
data("metabric", package = "SuperSurv")
dat <- metabric[1:80, ]
x_cols <- grep("^x", names(dat), value = TRUE)[1:5]
X <- dat[, x_cols, drop = FALSE]
new.times <- seq(20, 120, by = 20)

fit <- SuperSurv(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = X,
  new.times = new.times,
  event.library = c("surv.coxph"),
  cens.library = c("surv.coxph"),
  control = list(saveFitLibrary = TRUE)
)

tau_grid <- seq(40, 120, by = 20)
plot_marginal_rmst_curve(
  fit = fit,
  data = dat,
  trt_col = "x4",
  times = new.times,
  tau_seq = tau_grid
)
}


Waterfall Plot for an Individual Patient

Description

Waterfall Plot for an Individual Patient

Usage

plot_patient_waterfall(shap_values, patient_index = 1, top_n = 10)

Arguments

shap_values

The output from explain_kernel().

patient_index

The row index of the patient to explain

top_n

Number of features to show (default 10)

Value

A ggplot object visualizing the SHAP values.

Examples

if (FALSE) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  shap_values <- explain_kernel(
    model = fit,
    X_explain = X[1:10, , drop = FALSE],
    X_background = X[11:40, , drop = FALSE],
    nsim = 5, eval_time = 100
  )

  plot_patient_waterfall(
    shap_values = shap_values,
    patient_index = 1,
    top_n = 5
  )
}

Plot Predicted Survival Curves

Description

Plot Predicted Survival Curves

Usage

plot_predict(preds, eval_times, patient_idx = 1)

Arguments

preds

A list containing SuperSurv predictions OR a raw prediction matrix.

eval_times

Numeric vector of times at which predictions were evaluated.

patient_idx

Integer vector. Defaults to 1.

Value

A ggplot object.

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:120, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  eval_times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = eval_times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  preds <- predict(fit, newdata = X, new.times = eval_times, type = "event")

  plot_predict(
    preds = preds,
    eval_times = eval_times,
    patient_idx = c(1, 2)
  )
}

Plot Predicted RMST vs. Observed Survival Times

Description

Evaluates the calibration of the causal RMST estimator by plotting the model's predicted RMST for each patient against their actual observed follow-up time.

Usage

plot_rmst_vs_obs(fit, data, time_col, event_col, times, tau)

Arguments

fit

A fitted SuperSurv ensemble object.

data

A data.frame containing the patient covariates, times, and events.

time_col

Character string. The exact name of the observed follow-up time column in data.

event_col

Character string. The exact name of the event indicator column in data (e.g., 1 for event, 0 for censored).

times

Numeric vector of time points matching the prediction grid.

tau

Numeric. A single truncation time limit up to which the RMST is calculated.

Value

A ggplot object comparing predicted RMST to observed outcomes.

Examples

if (requireNamespace("ggplot2", quietly = TRUE)) {
data("metabric", package = "SuperSurv")
dat <- metabric[1:80, ]
x_cols <- grep("^x", names(dat))[1:5]
X <- dat[, x_cols, drop = FALSE]
new.times <- seq(20, 120, by = 20)

fit <- SuperSurv(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = X,
  new.times = new.times,
  event.library = c("surv.coxph"),
  cens.library = c("surv.coxph"),
  control = list(saveFitLibrary = TRUE)
)

plot_rmst_vs_obs(
  fit = fit,
  data = dat,
  time_col = "duration",
  event_col = "event",
  times = new.times,
  tau = 100
)
}

Survival Probability Heatmap

Description

Survival Probability Heatmap

Usage

plot_survival_heatmap(object, newdata, times)

Arguments

object

A fitted SuperSurv object

newdata

Test covariates (e.g., X_te[1:50, ])

times

The time grid to visualize

Value

A ggplot object visualizing the SHAP values.

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  plot_survival_heatmap(
    object = fit,
    newdata = X[1:20, , drop = FALSE],
    times = times
  )
}

Predict method for SuperSurv fits

Description

Obtains predicted survival probabilities from a fitted SuperSurv ensemble.

Usage

## S3 method for class 'SuperSurv'
predict(
  object,
  newdata,
  new.times,
  type = c("both", "event", "censoring"),
  onlySL = FALSE,
  threshold = 1e-04,
  ...
)

Arguments

object

A fitted object of class SuperSurv.

newdata

A data.frame of new covariate values.

new.times

A numeric vector of times at which to predict survival.

type

Character string specifying the prediction output. Use "event" for the event survival matrix, "censoring" for the censoring survival matrix, or "both" for the full list of outputs.

onlySL

Logical. If TRUE, only uses models with weights > threshold.

threshold

Numeric. The weight threshold for onlySL.

...

Additional ignored arguments.

Value

If type = "event" or type = "censoring", a numeric matrix with rows corresponding to observations and columns corresponding to new.times. If type = "both", a list containing:

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]
  newX <- X[1:10, , drop = FALSE]
  new.times <- seq(20, 120, by = 20)

  fit <- SuperSurv(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = X,
    new.times = new.times,
    event.library = c("surv.coxph", "surv.ridge"),
    cens.library = c("surv.coxph"),
    control = list(saveFitLibrary = TRUE)
  )

  pred_event <- predict(
    object = fit,
    newdata = newX,
    new.times = new.times,
    type = "event"
  )

  dim(pred_event)
}

Print a SuperSurv fit

Description

Prints a concise description of a fitted SuperSurv object.

Usage

## S3 method for class 'SuperSurv'
print(x, digits = max(3L, getOption("digits") - 3L), ...)

Arguments

x

A fitted object of class "SuperSurv".

digits

Number of significant digits to use for displayed weights.

...

Additional arguments ignored.

Value

The input object x, invisibly.


Keep All Variables Screener

Description

Keep All Variables Screener

Usage

screen.all(X, ...)

Arguments

X

Training covariate data.frame.

...

Additional ignored arguments.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:20, ]
x_cols <- grep("^x", names(dat))[1:5]
X <- dat[, x_cols, drop = FALSE]

screen.all(X)

Elastic Net Screening Algorithm

Description

This screening algorithm uses cv.glmnet to select covariates. Unlike LASSO (alpha = 1), which drops correlated features, Elastic Net (alpha = 0.5 by default) shrinks correlated groups of features together, making it ideal for selecting entire biological pathways.

Usage

screen.elasticnet(
  time,
  event,
  X,
  obsWeights = NULL,
  alpha = 0.5,
  minscreen = 2,
  nfolds = 10,
  nlambda = 100,
  ...
)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

X

Training covariate data.frame or matrix.

obsWeights

Numeric vector of observation weights.

alpha

Numeric penalty exponent for glmnet. Defaults to 0.5 (Elastic Net).

minscreen

Integer. Minimum number of covariates to return. Defaults to 2.

nfolds

Integer. Number of folds for cross-validation. Defaults to 10.

nlambda

Integer. Number of penalty parameters to search over. Defaults to 100.

...

Additional arguments passed to screen.glmnet.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]

  screen.elasticnet(
    time = dat$duration,
    event = dat$event,
    X = X,
    alpha = 0.5,
    minscreen = 2,
    nfolds = 3,
    nlambda = 20
  )
}

GLMNET (Lasso) Screening

Description

GLMNET (Lasso) Screening

Usage

screen.glmnet(
  time,
  event,
  X,
  obsWeights = NULL,
  alpha = 1,
  minscreen = 2,
  nfolds = 10,
  nlambda = 100,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data.frame.

obsWeights

Observation weights.

alpha

Penalty exponent (1 = lasso).

minscreen

Minimum number of covariates to return. Defaults to 2.

nfolds

Number of CV folds.

nlambda

Number of penalty parameters.

...

Additional ignored arguments.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

if (requireNamespace("glmnet", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]

  screen.glmnet(
    time = dat$duration,
    event = dat$event,
    X = X,
    alpha = 1,
    minscreen = 2,
    nfolds = 3,
    nlambda = 20
  )
}

Marginal Cox Regression Screening

Description

Marginal Cox Regression Screening

Usage

screen.marg(time, event, X, obsWeights = NULL, minscreen = 2, min.p = 0.1, ...)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data.frame.

obsWeights

Observation weights.

minscreen

Minimum number of covariates to return. Defaults to 2.

min.p

Threshold p-value. Defaults to 0.1.

...

Additional ignored arguments.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:40, ]
x_cols <- grep("^x", names(dat))[1:5]
X <- dat[, x_cols, drop = FALSE]

screen.marg(
  time = dat$duration,
  event = dat$event,
  X = X,
  minscreen = 2,
  min.p = 0.2
)

Random Survival Forest Screening Algorithm

Description

This screening algorithm uses the randomForestSRC package to select covariates based on their Variable Importance (VIMP). It grows a fast forest and retains features with a VIMP greater than zero.

Usage

screen.rfsrc(
  time,
  event,
  X,
  obsWeights = NULL,
  minscreen = 2,
  ntree = 100,
  ...
)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

X

Training covariate data.frame or matrix.

obsWeights

Numeric vector of observation weights.

minscreen

Integer. Minimum number of covariates to return. Defaults to 2.

ntree

Integer. Number of trees to grow. Defaults to 100 for fast screening.

...

Additional arguments passed to rfsrc.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

if (requireNamespace("randomForestSRC", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  x_cols <- grep("^x", names(dat))[1:5]
  X <- dat[, x_cols, drop = FALSE]

  screen.rfsrc(
    time = dat$duration,
    event = dat$event,
    X = X,
    minscreen = 2,
    ntree = 10
  )
}

High Variance Screening Algorithm (Unsupervised)

Description

An unsupervised screening algorithm that filters out low-variance features. This is particularly useful for high-dimensional genomic or transcriptomic data where many features remain relatively constant across all observations.

Usage

screen.var(
  time,
  event,
  X,
  obsWeights = NULL,
  keep_fraction = 0.5,
  minscreen = 2,
  ...
)

Arguments

time

Numeric vector of observed follow-up times (Ignored internally).

event

Numeric vector of event indicators (Ignored internally).

X

Training covariate data.frame or matrix.

obsWeights

Numeric vector of observation weights (Ignored internally).

keep_fraction

Numeric value between 0 and 1. The fraction of highest-variance features to retain. Defaults to 0.5 (keeps the top 50%).

minscreen

Integer. Minimum number of covariates to return. Defaults to 2.

...

Additional ignored arguments.

Value

A logical vector of the same length as the number of columns in X, indicating which variables passed the screening algorithm (TRUE to keep, FALSE to drop).

Examples

data("metabric", package = "SuperSurv")
dat <- metabric[1:40, ]
x_cols <- grep("^x", names(dat))[1:6]
X <- dat[, x_cols, drop = FALSE]

screen.var(
  time = dat$duration,
  event = dat$event,
  X = X,
  keep_fraction = 0.5,
  minscreen = 2
)

Access variables selected by SuperSurv screeners

Description

Returns the variables retained by a screening step for one or more fitted event or censoring learners.

Usage

selected_variables(object, ...)

## Default S3 method:
selected_variables(object, ...)

## S3 method for class 'SuperSurv'
selected_variables(object, type = c("event", "censoring"), learner = NULL, ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

type

Character string specifying whether to inspect event or censoring learners.

learner

Optional learner index or learner name. If omitted, selected variables are returned for every learner of the requested type.

Value

A named list of character vectors, or a single character vector when learner has length one.


Summarize a SuperSurv fit

Description

Summarizes the fitted event and censoring ensembles, including learner names, ensemble weights, cross-validated risks, error flags, prediction dimensions, and recorded timing information.

Usage

## S3 method for class 'SuperSurv'
summary(object, ...)

## S3 method for class 'summary.SuperSurv'
print(x, digits = max(3L, getOption("digits") - 3L), ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

x

A summary object produced by summary.SuperSurv().

digits

Number of significant digits to use for displayed weights and risks.

Value

An object of class "summary.SuperSurv", a list containing the matched call, selection mode, event and censoring learner summaries, prediction dimensions, and timing information.


Wrapper for AORSF (Oblique Random Survival Forest)

Description

Final Production Wrapper for AORSF (Tunable & Robust).

Usage

surv.aorsf(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  n_tree = 500,
  leaf_min_events = 5,
  mtry = NULL,
  ...
)

Arguments

time

Observed follow-up time; i.e. minimum of the event and censoring times.

event

Observed event indicator; i.e, whether the follow-up time corresponds to an event or censoring.

X

Training covariate data.frame.

newdata

Test covariate data.frame to use for prediction. Should have the same variable names and structure as X.

new.times

Times at which to obtain the predicted survivals.

obsWeights

Observation weights.

id

Optional cluster/individual ID indicator.

n_tree

Number of trees to grow (default: 500).

leaf_min_events

Minimum number of events in a leaf node (default: 5).

mtry

Number of predictors evaluated at each node.

...

Additional arguments passed to orsf.

Value

A list containing:

Examples

if (requireNamespace("aorsf", 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.aorsf(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    n_tree = 10,
    leaf_min_events = 2
  )

  dim(fit[["pred"]])
}

Wrapper for BART (Bayesian Additive Regression Trees)

Description

Final Production Wrapper for BART (Tunable & Robust). Uses the mc.surv.bart function. Automatically reshapes the flat output vector into a survival matrix and interpolates the predictions to the requested new.times.

Usage

surv.bart(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  ntree = 10,
  ndpost = 30,
  nskip = 10,
  ...
)

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 predicted survivals.

obsWeights

Observation weights (Note: BART does not natively support weights).

id

Optional cluster/individual ID indicator.

ntree

Number of trees (default: 50).

ndpost

Number of posterior draws (default: 1000).

nskip

Number of burn-in draws (default: 250).

...

Additional arguments passed to mc.surv.bart.

Value

A list containing:

Examples

## Not run: 
if (.Platform$OS.type != "windows" &&
  requireNamespace("BART", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:20, ]
  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.bart(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    ntree = 3,
    ndpost = 5,
    nskip = 5
  )

  dim(fit[["pred"]])
}

## End(Not run)

Wrapper function for Component-Wise Boosting (CoxBoost)

Description

Final Production Wrapper for CoxBoost (Tunable & Robust). Estimates a Cox model via component-wise likelihood based boosting.

Usage

surv.coxboost(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  stepno = 100,
  penalty = 100,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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 (Note: CoxBoost does not natively support weights, so these are ignored).

id

Optional cluster/individual ID indicator.

stepno

Number of boosting steps (default: 100).

penalty

Penalty value for the update (default: 100).

ties

Tied-event approximation used for risk-score calibration: "breslow" (default) or "efron".

survival_transform

Transformation from calibrated hazard increments to survival probabilities: "exponential" (default) or "product_limit".

...

Additional arguments passed to CoxBoost.

Value

A list containing:

Examples

if (requireNamespace("CoxBoost", 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.coxboost(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    stepno = 10,
    penalty = 50
  )

  dim(fit[["pred"]])
}

Wrapper for standard Cox Proportional Hazards

Description

Final Production Wrapper for CoxPH. Uses partial maximum likelihood and the Breslow estimator.

Usage

surv.coxph(time, event, X, newdata, new.times, obsWeights, id, ...)

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 predicted survivals.

obsWeights

Observation weights.

id

Optional cluster/individual ID indicator.

...

Additional arguments passed to coxph.

Value

A list containing:

Examples

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.coxph(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Experimental Cox-Time Neural Survival Learner

Description

Fits a neural Cox-Time model allowing time-dependent covariate effects through survivalmodels::coxtime(). This optional adapter requires Python torch, torchtuples, and pycox and supports only uniform observation weights.

Usage

surv.coxtime(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  num_nodes = c(32L, 32L),
  activation = "relu",
  batch_norm = TRUE,
  dropout = NULL,
  epochs = 100L,
  batch_size = 128L,
  device = NULL,
  verbose = FALSE,
  seed = 1L,
  standardize_time = TRUE,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

num_nodes

Positive integers giving hidden-layer sizes.

activation

Neural-network activation name.

batch_norm

Whether to use batch normalization.

dropout

Optional dropout probability in ⁠[0, 1)⁠.

epochs

Number of training epochs.

batch_size

Training and prediction batch size.

device

Optional device passed to survivalmodels.

verbose

Whether the Python backend should print training progress.

seed

Positive integer used for Python, NumPy, and torch random-number generators.

standardize_time

Whether to standardize outcome times using the training-only Cox-Time label transformation. Predictions are returned on the original time scale.

...

Additional named fitting arguments passed to survivalmodels::coxtime(), such as frac for an internal training-fold validation split or early_stopping. Outcomes and features are managed by the adapter.

Details

Native survival curves are evaluated as right-continuous steps on the backend's time grid, using survival one before the first grid point and the final available value beyond the last point. This is not a claim of reliable extrapolation beyond observed follow-up. Python-backed fitted objects are intended for reuse within the active R/Python session; plain saveRDS() is not a portable persistence format for Python objects.

Value

A list with numeric survival matrix pred and fitted object fit.

Examples

if (interactive() && requireNamespace("survivalmodels", quietly = TRUE) &&
    requireNamespace("reticulate", quietly = TRUE) &&
    reticulate::py_module_available("pycox")) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:60, ]
  X <- dat[, "x1", drop = FALSE]
  fit <- surv.coxtime(dat$duration, dat$event, X,
                      X[1:3, , drop = FALSE], c(50, 100),
                      epochs = 2, batch_norm = FALSE, device = "cpu")
  dim(fit$pred)
}

Experimental DeepHit Learner

Description

Fits a single-event discrete-time DeepHit neural network through survivalmodels::deephit(). This optional adapter requires a Python environment containing torch, torchtuples, and pycox and currently supports only uniform observation weights.

Usage

surv.deephit(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  num_nodes = c(32L, 32L),
  activation = "relu",
  batch_norm = TRUE,
  dropout = NULL,
  epochs = 100L,
  batch_size = 128L,
  device = NULL,
  verbose = FALSE,
  seed = 1L,
  cuts = 20L,
  cutpoints = NULL,
  scheme = c("equidistant", "quantiles"),
  mod_alpha = 0.2,
  sigma = 0.1,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

num_nodes

Positive integers giving hidden-layer sizes.

activation

Neural-network activation name.

batch_norm

Whether to use batch normalization.

dropout

Optional dropout probability in ⁠[0, 1)⁠.

epochs

Number of training epochs.

batch_size

Training and prediction batch size.

device

Optional device passed to survivalmodels.

verbose

Whether the Python backend should print training progress.

seed

Positive integer used for Python, NumPy, and torch random-number generators.

cuts

Number of discrete time intervals, or a vector of cut points supplied through cutpoints.

cutpoints

Optional numeric vector of cut points.

scheme

Cut-point scheme used when cutpoints is NULL.

mod_alpha

Weight placed on the likelihood component of the DeepHit objective.

sigma

Ranking-loss bandwidth.

...

Additional arguments passed to survivalmodels::deephit().

Details

Fitted Python objects can be reused in the active R/Python session. Plain saveRDS() is not a portable persistence format for these objects. Native survival curves are mapped to requested times as right-continuous steps; see surv.coxtime() for the boundary convention.

Value

A list with numeric matrix pred and fitted object fit.

Examples

if (interactive() && requireNamespace("survivalmodels", quietly = TRUE) &&
    requireNamespace("reticulate", quietly = TRUE) &&
    reticulate::py_module_available("pycox")) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:60, ]
  X <- dat[, grep("^x", names(dat))[1:3], drop = FALSE]
  fit <- surv.deephit(
    dat$duration, dat$event, X, X[1:4, , drop = FALSE],
    c(50, 100), cuts = 10, epochs = 2, seed = 1
  )
  dim(fit$pred)
}

Experimental DeepSurv Learner

Description

Fits a Cox partial-likelihood neural network through survivalmodels::deepsurv(). This optional adapter requires a Python environment containing torch, torchtuples, and pycox and currently supports only uniform observation weights.

Usage

surv.deepsurv(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  num_nodes = c(32L, 32L),
  activation = "relu",
  batch_norm = TRUE,
  dropout = NULL,
  epochs = 100L,
  batch_size = 128L,
  device = NULL,
  verbose = FALSE,
  seed = 1L,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

num_nodes

Positive integers giving hidden-layer sizes.

activation

Neural-network activation name.

batch_norm

Whether to use batch normalization.

dropout

Optional dropout probability in ⁠[0, 1)⁠.

epochs

Number of training epochs.

batch_size

Training and prediction batch size.

device

Optional device passed to survivalmodels.

verbose

Whether the Python backend should print training progress.

seed

Positive integer used for Python, NumPy, and torch random-number generators.

...

Additional arguments passed to survivalmodels::deepsurv().

Details

Fitted Python objects can be reused in the active R/Python session. Plain saveRDS() is not a portable persistence format for these objects. Native survival curves are mapped to requested times as right-continuous steps; see surv.coxtime() for the boundary convention.

Value

A list with numeric matrix pred and fitted object fit.

Examples

if (interactive() && requireNamespace("survivalmodels", quietly = TRUE) &&
    requireNamespace("reticulate", quietly = TRUE) &&
    reticulate::py_module_available("pycox")) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:60, ]
  X <- dat[, grep("^x", names(dat))[1:3], drop = FALSE]
  fit <- surv.deepsurv(
    dat$duration, dat$event, X, X[1:4, , drop = FALSE],
    c(50, 100), epochs = 2, seed = 1
  )
  dim(fit$pred)
}

Parametric Survival Prediction Wrapper (Exponential)

Description

Parametric Survival Prediction Wrapper (Exponential)

Usage

surv.exponential(time, event, X, newdata, new.times, obsWeights, id, ...)

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

Cluster identification variable.

...

Additional ignored arguments.

Value

A list containing the fitted model and predictions.

Examples

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.exponential(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Flexible Parametric Distribution Survival Learner

Description

Fits a weighted parametric survival model using flexsurv::flexsurvreg(). Native survival probabilities are used without risk-score calibration.

Usage

surv.flexsurvreg(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  dist = "gengamma",
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

dist

Distribution: "gengamma" (generalized gamma, default), "gompertz", "gamma", "weibull", "exp", "lnorm", or "llogis".

...

Additional named arguments to flexsurv::flexsurvreg(), such as inits, anc, or optimizer control. Outcome, data, weight, truncation, and relative-survival arguments are managed or excluded by this adapter.

Details

Only single-event, right-censored outcomes are supported. Covariates enter the distribution's location parameter by default; anc can specify covariates on ancillary parameters. Generalized gamma may require suitable initial values, especially in small training folds. Failed optimization is reported as an error rather than silently accepted.

Value

A list with numeric survival matrix pred and fitted object fit.

Examples

if (requireNamespace("flexsurv", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  X <- dat[, "x1", drop = FALSE]
  fit <- surv.flexsurvreg(dat$duration, dat$event, X,
                         X[1:3, , drop = FALSE], c(50, 100), dist = "weibull")
  predict(fit$fit, X[1:3, , drop = FALSE], new.times = c(25, 50, 100))
}

Flexible Parametric Spline Survival Learner

Description

Fits a weighted Royston-Parmar flexible parametric survival model using flexsurv::flexsurvspline().

Usage

surv.flexsurvspline(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  k = 1L,
  scale = "hazard",
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

k

Number of internal spline knots.

scale

Scale on which the flexible model is defined.

...

Additional arguments passed to flexsurv::flexsurvspline().

Value

A list with numeric matrix pred and fitted object fit.

Examples

if (requireNamespace("flexsurv", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  X <- dat[, grep("^x", names(dat))[1:3], drop = FALSE]
  fit <- surv.flexsurvspline(
    dat$duration, dat$event, X, X[1:4, , drop = FALSE],
    c(50, 100), k = 1
  )
  dim(fit$pred)
}

Wrapper for Generalized Additive Cox Regression (GAM)

Description

Final Production Wrapper for GAM (Tunable & Robust). Uses gam to fit an additive combination of smooth and linear functions.

Usage

surv.gam(time, event, X, newdata, new.times, obsWeights, id, cts.num = 5, ...)

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 predicted survivals.

obsWeights

Observation weights (Note: Ignored, as mgcv uses weights for the event indicator).

id

Optional cluster/individual ID indicator.

cts.num

Cutoff of unique values at which a numeric covariate receives a smooth term (s).

...

Additional arguments passed to gam.

Value

A list containing:

Examples

if (requireNamespace("mgcv", 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.gam(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    cts.num = 5
  )

  dim(fit[["pred"]])
}

Wrapper function for Gradient Boosting (GBM) prediction algorithm

Description

Final Production Wrapper for GBM (Tunable & Robust). Estimates a Cox proportional hazards model via gradient boosting. Uses the Breslow estimator with a step-function approach for the baseline hazard. Includes internal safeguards against C++ crashes and small cross-validation folds.

Usage

surv.gbm(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  n.trees = 1000,
  interaction.depth = 2,
  shrinkage = 0.01,
  cv.folds = 5,
  n.minobsinnode = 10,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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

Optional cluster/individual ID indicator.

n.trees

Integer specifying the total number of trees to fit (default: 1000).

interaction.depth

Maximum depth of variable interactions (default: 2).

shrinkage

A shrinkage parameter applied to each tree (default: 0.01).

cv.folds

Number of cross-validation folds to perform internally for optimal tree selection (default: 5).

n.minobsinnode

Minimum number of observations in the trees terminal nodes (default: 10).

ties

Tied-event approximation used for risk-score calibration: "breslow" (default) or "efron".

survival_transform

Transformation from calibrated hazard increments to survival probabilities: "exponential" (default) or "product_limit".

...

Additional arguments passed to gbm.

Value

A list containing:

Examples

if (requireNamespace("gbm", 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.gbm(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    n.trees = 20,
    interaction.depth = 1,
    shrinkage = 0.05,
    cv.folds = 0,
    n.minobsinnode = 3
  )

  dim(fit[["pred"]])
}

Wrapper function for Penalized Cox Regression (GLMNET)

Description

Final Production Wrapper for GLMNET (Tunable & Robust). Estimates a penalized Cox model (Lasso, Ridge, or Elastic Net) with automatic lambda selection. Uses the Breslow estimator with a step-function approach for the baseline hazard.

Usage

surv.glmnet(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  alpha = 1,
  nfolds = 10,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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

Optional cluster/individual ID indicator.

alpha

The elasticnet mixing parameter (0 = Ridge, 1 = Lasso). Default is 1.

nfolds

Number of folds for internal cross-validation to select lambda. Default is 10.

ties

Tied-event approximation used to recover the baseline cumulative hazard from the fitted risk score. Either "breslow" (default) or "efron".

survival_transform

Transformation used to convert calibrated hazard increments to survival probabilities. Either "exponential" (default) or "product_limit".

...

Additional arguments passed to cv.glmnet.

Value

A list containing:

Examples

if (requireNamespace("glmnet", 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.glmnet(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    alpha = 1,
    nfolds = 3
  )

  dim(fit[["pred"]])
}

Generalized Random Survival Forest Learner

Description

Fits an honest generalized random survival forest using grf::survival_forest() and returns conditional survival curves.

Usage

surv.grf(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  num.trees = 1000L,
  mtry = NULL,
  min.node.size = 15L,
  honesty = TRUE,
  prediction.type = c("Kaplan-Meier", "Nelson-Aalen"),
  seed = 1L,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

num.trees

Number of trees.

mtry

Number of candidate variables considered at each split.

min.node.size

Minimum terminal-node size.

honesty

Whether to use honest sample splitting.

prediction.type

Either "Kaplan-Meier" or "Nelson-Aalen".

seed

Integer random seed passed to grf.

...

Additional arguments passed to grf::survival_forest().

Value

A list with numeric matrix pred and fitted object fit.

Examples

if (requireNamespace("grf", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  X <- dat[, grep("^x", names(dat))[1:3], drop = FALSE]
  fit <- surv.grf(
    dat$duration, dat$event, X, X[1:4, , drop = FALSE],
    c(50, 100), num.trees = 50, seed = 1
  )
  dim(fit$pred)
}

Kaplan-Meier Prediction Algorithm

Description

This prediction algorithm ignores all covariates and computes the marginal Kaplan-Meier survival estimator using the survfit function.

Usage

surv.km(time, event, X, newdata, new.times, obsWeights, id, ...)

Arguments

time

Numeric vector of observed follow-up times.

event

Numeric vector of event indicators (1 = event, 0 = censored).

X

Training covariate data.frame (Ignored by KM).

newdata

Test covariate data.frame to use for prediction.

new.times

Numeric vector of times at which to predict survival.

obsWeights

Numeric vector of observation weights.

id

Optional vector indicating subject/cluster identities.

...

Additional ignored arguments.

Value

A list containing:

Examples

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.km(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Parametric Survival Prediction Wrapper (Log-Logistic)

Description

Parametric Survival Prediction Wrapper (Log-Logistic)

Usage

surv.loglogistic(time, event, X, newdata, new.times, obsWeights, id, ...)

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

Cluster identification variable.

...

Additional ignored arguments.

Value

A list containing the fitted model and predictions.

Examples

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.loglogistic(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Parametric Survival Prediction Wrapper (Log-Normal)

Description

Parametric Survival Prediction Wrapper (Log-Normal)

Usage

surv.lognormal(time, event, X, newdata, new.times, obsWeights, id, ...)

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

Cluster identification variable.

...

Additional ignored arguments.

Value

A list containing the fitted model and predictions.

Examples

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.lognormal(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Component-Wise Cox Boosting Learner

Description

Fits a weighted component-wise Cox proportional-hazards model using mboost::glmboost() and converts its risk score to survival probabilities using SuperSurv's weighted baseline-hazard calibration.

Usage

surv.mboost(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  mstop = 100L,
  nu = 0.1,
  center = FALSE,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

mstop

Number of boosting iterations.

nu

Boosting step size.

center

Whether to center component-wise base learners.

ties

Tied-event approximation for risk-score calibration.

survival_transform

Transformation from calibrated hazard increments to survival probabilities.

...

Additional arguments passed to mboost::glmboost().

Value

A list with numeric matrix pred and fitted object fit.

Examples

if (requireNamespace("mboost", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:40, ]
  X <- dat[, grep("^x", names(dat))[1:3], drop = FALSE]
  fit <- surv.mboost(
    dat$duration, dat$event, X, X[1:4, , drop = FALSE],
    c(50, 100), mstop = 20
  )
  dim(fit$pred)
}

Universal Parametric Survival Wrapper

Description

Final Production Wrapper for AFT Models (Weibull, Exponential, LogNormal, LogLogistic). Replaces individual wrappers with one robust, vectorized function.

Usage

surv.parametric(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  dist = "weibull",
  ...
)

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 predicted survivals.

obsWeights

Observation weights.

id

Optional cluster/individual ID indicator.

dist

Distribution for the AFT model (default: "weibull").

...

Additional arguments passed to survreg.

Value

A list containing:

Examples

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.parametric(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL,
  dist = "weibull"
)

dim(fit[["pred"]])

Wrapper function for Ranger Random Survival Forest

Description

Final Production Wrapper for Ranger (Tunable & Fast). Uses the ranger C++ implementation to estimate survival curves.

Usage

surv.ranger(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  num.trees = 500,
  mtry = NULL,
  min.node.size = 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 predicted survivals.

obsWeights

Observation weights.

id

Optional cluster/individual ID indicator.

num.trees

Number of trees (default: 500).

mtry

Number of variables to split at each node. Defaults to sqrt(p).

min.node.size

Minimum node size (default: 15 for survival).

...

Additional arguments passed to ranger.

Value

A list containing:

Examples

if (requireNamespace("ranger", 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.ranger(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    num.trees = 10,
    min.node.size = 3
  )

  dim(fit[["pred"]])
}

Wrapper function for Random Survival Forests (RFSRC)

Description

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:

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"]])
}

Wrapper for Ridge Regression (Penalized Cox)

Description

Final Production Wrapper for Ridge Regression (Tunable & Robust). Estimates a penalized Cox model using a pure Ridge penalty (alpha = 0).

Usage

surv.ridge(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights = NULL,
  id = NULL,
  nfolds = 10,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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

Optional cluster/individual ID indicator.

nfolds

Number of folds for internal cross-validation to select lambda. Default is 10.

ties

Tied-event approximation used for risk-score calibration: "breslow" (default) or "efron".

survival_transform

Transformation from calibrated hazard increments to survival probabilities: "exponential" (default) or "product_limit".

...

Additional arguments passed to cv.glmnet.

Value

A list containing:

Examples

if (requireNamespace("glmnet", 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.ridge(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    nfolds = 3
  )

  dim(fit[["pred"]])
}

Wrapper for Survival Regression Trees (rpart)

Description

Final Production Wrapper for single decision trees. Uses rpart with method="exp" and calculates survival probabilities using the Breslow estimator.

Usage

surv.rpart(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  cp = 0.01,
  minsplit = 20,
  maxdepth = 30,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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 predicted survivals.

obsWeights

Observation weights.

id

Optional cluster/individual ID indicator.

cp

Complexity parameter (default: 0.01).

minsplit

Minimum number of observations to attempt a split (default: 20).

maxdepth

Maximum depth of any node of the final tree (default: 30).

ties

Tied-event approximation used for risk-score calibration: "breslow" (default) or "efron".

survival_transform

Transformation from calibrated hazard increments to survival probabilities: "exponential" (default) or "product_limit".

...

Additional arguments passed to rpart.control.

Value

A list containing:

Examples

if (requireNamespace("rpart", 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.rpart(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    cp = 0.01,
    minsplit = 5,
    maxdepth = 3
  )

  dim(fit[["pred"]])
}

Penalized Smooth Hazard Survival Learner

Description

Fits an overall hazard model using survPen::survPen() and returns its native survival probabilities. Only single-event, right-censored outcomes and uniform observation weights are supported.

Usage

surv.survPen(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights = NULL,
  id = NULL,
  formula = NULL,
  baseline.df = 4L,
  n.legendre = 50L,
  ...
)

Arguments

time

Observed follow-up time.

event

Observed event indicator.

X

Training covariate data frame.

newdata

Covariate data frame used for prediction.

new.times

Times at which survival probabilities are requested.

obsWeights

Optional non-negative observation weights.

id

Currently ignored.

formula

Optional one-sided hazard formula using feature names and .supersurv_time. For example, ~ smf(.supersurv_time, df = 4) + smf(x1, df = 4) + x2, or ~ tensor(.supersurv_time, x1, df = c(4, 4)) + x2 for a time-varying effect. The survPen constructors smf, tensor, tint, and rd are available without attaching the backend package. Formula variables must come from the current training features or .supersurv_time.

baseline.df

Baseline smooth degrees of freedom, at least 3. Used only when formula is NULL; the default adds linear terms for all features to smf(.supersurv_time, df = baseline.df).

n.legendre

Positive integer quadrature order for both fitting and survival prediction. Increase this to check integration accuracy.

...

Additional named fitting controls passed to survPen::survPen(), such as lambda, method, or max.it.beta.

Details

Nonuniform observation weights are rejected because the backend does not expose case-weighted fitting. The adapter does not implement net survival, relative mortality, or left truncation. Survival curves that increase beyond numerical tolerance cause an error; increase quadrature accuracy rather than silently projecting a materially invalid curve. Custom formulas must remain valid after feature screening; use screen.all when explicitly naming features.

Value

A list with numeric survival matrix pred and fitted object fit.

Examples

if (requireNamespace("survPen", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:80, ]
  X <- dat[, "x1", drop = FALSE]
  fit <- surv.survPen(dat$duration, dat$event, X,
                      X[1:3, , drop = FALSE], c(50, 100), baseline.df = 3)
  dim(fit$pred)
}

Wrapper for Survival Support Vector Machine (survivalsvm)

Description

Final Production Wrapper for SVM (Tunable & Robust). Estimates a survival SVM and calibrates the raw utility scores into survival probabilities using a univariate Cox proportional hazards model.

Usage

surv.svm(
  time,
  event,
  X,
  newdata,
  new.times,
  obsWeights,
  id,
  gamma.mu = 0.1,
  type = "vanbelle2",
  kernel = "lin_kernel",
  opt.meth = "quadprog",
  ...
)

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

Optional cluster/individual ID indicator.

gamma.mu

Regularization parameter for the SVM (default: 0.1).

type

Type of SVM implementation (default: "vanbelle2").

kernel

Kernel type for the SVM (default: "lin_kernel").

opt.meth

Optimization method (default: "quadprog").

...

Additional arguments passed to survivalsvm.

Value

A list containing:

Examples

if (requireNamespace("survivalsvm", quietly = TRUE) &&
 requireNamespace("quadprog", quietly = TRUE)) {
  data("metabric", package = "SuperSurv")
  dat <- metabric[1:25, ]
  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.svm(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times
  )

  dim(fit[["pred"]])
}

Parametric Survival Prediction Wrapper (Weibull)

Description

Parametric Survival Prediction Wrapper (Weibull)

Usage

surv.weibull(time, event, X, newdata, new.times, obsWeights, id, ...)

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

Cluster identification variable.

...

Additional ignored arguments.

Value

A list containing the fitted model and predictions.

Examples

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.weibull(
  time = dat$duration,
  event = dat$event,
  X = X,
  newdata = newX,
  new.times = times,
  obsWeights = rep(1, nrow(dat)),
  id = NULL
)

dim(fit[["pred"]])

Wrapper for XGBoost (Robust CV-Tuned + Safe Prediction)

Description

Estimates a Cox proportional hazards model via XGBoost. Incorporates safe Breslow hazard calculation and matrix alignment to prevent C++ crashes.

Usage

surv.xgboost(
  time,
  event,
  X,
  newdata = NULL,
  new.times,
  obsWeights,
  id,
  nrounds = 1000,
  early_stopping_rounds = 10,
  eta = 0.05,
  max_depth = 2,
  min_child_weight = 5,
  lambda = 10,
  subsample = 0.7,
  ties = c("breslow", "efron"),
  survival_transform = c("exponential", "product_limit"),
  ...
)

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

Optional cluster/individual ID indicator.

nrounds

Max number of boosting iterations (default: 1000).

early_stopping_rounds

Rounds with no improvement to trigger early stopping (default: 10).

eta

Learning rate (default: 0.05).

max_depth

Maximum tree depth (default: 2).

min_child_weight

Minimum sum of instance weight in a child (default: 5).

lambda

L2 regularization term on weights (default: 10).

subsample

Subsample ratio of the training instances (default: 0.7).

ties

Tied-event approximation used for risk-score calibration: "breslow" (default) or "efron".

survival_transform

Transformation from calibrated hazard increments to survival probabilities: "exponential" (default) or "product_limit".

...

Additional arguments passed to xgb.train.

Value

A list containing:

Examples

if (interactive() && requireNamespace("xgboost", 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.xgboost(
    time = dat$duration,
    event = dat$event,
    X = X,
    newdata = newX,
    new.times = times,
    obsWeights = rep(1, nrow(dat)),
    id = NULL,
    nrounds = 5,
    early_stopping_rounds = 2,
    max_depth = 1,
    nthread = 1
  )

  dim(fit[["pred"]])
}

Access SuperSurv training variable names

Description

Returns the covariate names used to fit a SuperSurv object.

Usage

training_variables(object, ...)

## Default S3 method:
training_variables(object, ...)

## S3 method for class 'SuperSurv'
training_variables(object, ...)

Arguments

object

A fitted object of class "SuperSurv".

...

Additional arguments ignored.

Value

A character vector of training variable names.