Implements a Stacking ensemble for prognostic models. It trains multiple base models and uses their predictions to train a meta-model.
Usage
stacking_pro(
results_all_models,
data,
meta_model_name,
top = 3,
tune_meta = FALSE,
time_unit = "day",
years_to_evaluate = c(1, 3, 5),
seed = 789
)
Arguments
- results_all_models
A list of results from
models_pro()
, containing trained base model objects and their evaluation metrics.- data
A data frame for training the meta-model. The first column must be ID, second event status (0/1), third time, and subsequent columns features.
- meta_model_name
A character string, the name of the meta-model to use (e.g., "lasso_pro", "gbm_pro"). This model must be registered.
- top
An integer, the number of top-performing base models (ranked by C-index) to select for the stacking ensemble.
- tune_meta
Logical, whether to enable tuning for the meta-model.
- time_unit
A character string, the unit of time in the third column of
data
.- years_to_evaluate
A numeric vector of specific years at which to calculate time-dependent AUROC for evaluation.
- seed
An integer, for reproducibility.
Examples
# \donttest{
# NOTE: This example requires the 'train_pro' dataset.
if (requireNamespace("E2E", quietly = TRUE) &&
"train_pro" %in% utils::data(package = "E2E")$results[,3]) {
data(train_pro, package = "E2E")
initialize_modeling_system_pro()
# First, generate results for base models
base_model_results <- models_pro(data = train_pro, model = c("lasso_pro", "rsf_pro"))
# Then, create the stacking ensemble
stacking_lasso_results <- stacking_pro(
results_all_models = base_model_results,
data = train_pro,
meta_model_name = "lasso_pro",
top = 3,
years_to_evaluate = c(1, 3)
)
print_model_summary_pro("Stacking (Lasso)", stacking_lasso_results)
}
#> Prognosis modeling system already initialized.
#> Running model: lasso_pro
#> Running model: rsf_pro
#> Running Stacking model: Stacking_pro (meta: lasso_pro)
#>
#> --- Stacking (Lasso) Prognosis Model (on Training Data) Metrics ---
#> Ensemble Type: Stacking (Meta: lasso_pro, Base models used: rsf_pro, lasso_pro)
#> C-index: 0.8814
#> Time-dependent AUROC (years 1, 3): 0.7389, 0.8173
#> Average Time-dependent AUROC: 0.7781
#> KM Group HR (High vs Low): 19.5197 (p-value: 3.159e-18, Cutoff: 18.0175)
#> --------------------------------------------------
# }