Skip to contents

Learner_xgboost is a Reference Class implementing the learner interface used by Superlearner() and fit_learner().

Usage

Learner_xgboost(...)

Arguments

...

Initialization arguments described in the Initialization arguments section.

Details

User-facing API: users should initialize the learner with Learner_xgboost(...) and pass the resulting object to Superlearner() or fit_learner(). The remaining methods documented below implement the internal learner interface and are not intended to be called directly.

Wrapper role: this class fits gradient-boosted Poisson models to the package's long-format representation of piecewise-constant hazards. Time at risk is supplied to xgboost as a log-exposure base margin, and interval (node) indicators are included in the design matrix to represent the baseline hazard. In competing-risks settings, one booster is fit per cause.

The xgboost package is an optional dependency and must be installed before constructing or fitting this learner.

Model

Let \(0=t_0 < t_1 < \cdots < t_m\) denote the time grid and let \(I_k(t)\) indicate interval \(k\). The learner models the piecewise-constant hazard as $$ \lambda(t \mid x) = \sum_{k=0}^{m} I_k(t)\,\exp\{f(x,k)\}, $$ Here, \(f(x,k)\) is learned by gradient-boosted trees using the count:poisson objective by default. The response is the interval-specific event count and log(tij) is used as the exposure offset through the base_margin supplied to xgboost.

Initialization arguments

covariates

character. Names or formula terms used as predictors. The underlying column names are recovered from these terms when preparing fitting and prediction data. The interval factor node is added automatically.

cross_validation

logical(1). If TRUE, use xgboost::xgb.cv() to select the number of boosting rounds before fitting the final model.

params

Named list of xgboost parameters. User-supplied entries override the defaults: objective = "count:poisson", eval_metric = "poisson-nloglik", eta = 0.01, max_depth = 2, alpha = 0.5, and lambda = 0.5.

nrounds

Positive number giving the maximum number of boosting rounds. When cross-validation is enabled, the selected best iteration is used for the final fit.

nfold

Positive number of folds used by xgboost::xgb.cv().

early_stopping_rounds

Number of rounds without improvement allowed in cross-validation. Set to a non-positive or non-finite value to omit early stopping.

verbose

Verbosity passed to the xgboost fitting functions.

...

Additional arguments forwarded to xgboost::xgb.cv() and xgboost::xgb.train().

Fields

covariates (character)

Predictor terms supplied at initialization.

basic_covariates (character)

Underlying column names recovered from the predictor terms.

cross_validation (logical)

Whether boosting rounds are selected by cross-validation.

formula (character)

Formula used to construct the long-format design matrix, including the node indicators and exposure offset.

params (list)

Merged default and user-supplied xgboost parameters.

nrounds, nfold, early_stopping_rounds, verbose (numeric)

Controls passed to the xgboost fitting workflow.

fit_arguments (list)

Additional backend arguments supplied in ....

learner (function)

The configured backend entry point, xgboost::xgb.cv or xgboost::xgb.train.

baseline_model (list)

Storage reserved for fitted baseline adjustments.

rebalance (logical)

Reserved field for baseline-hazard rebalancing.

Fitted models

Each cause-specific fit has class psl_xgboost and stores the fitted booster, model terms, design-matrix column names, factor levels, cause label, selected number of rounds, and fitting parameters. Prediction reconstructs the same design matrix and returns hazards on the response scale. Backend failures are represented by the package's failed-fit sentinel so ensemble fitting can continue with the remaining learners.

Methods (internal learner interface)

initialize(...)

Construct and configure the learner. This is the only method users should call.

basic_covariates_constructor(covs)

Internal. Recover data-column names from predictor terms.

private_fit(data, ...)

Internal. Fit one cause-specific boosted Poisson model on long-format data.

private_fit_all_causes(data, ...)

Internal. Fit all cause-specific models using a shared long-format design.

private_predictor(model, newdata, ...)

Internal. Reconstruct the node-expanded design matrix and predict hazards.

Examples

if (requireNamespace("xgboost", quietly = TRUE)) {
  lrn <- Learner_xgboost(
    covariates = c("age", "value_LDL"),
    nrounds = 100,
    nfold = 3,
    early_stopping_rounds = 10
  )
}