Error: No eligible apparent-screen combinations remain.

test_that("cindex_harrell: handles edge cases", {
# internal function, called through the same namespace via ::: in tests
# perfect concordance: higher risk -> shorter time (all events)
test_that("loocv_cindex with a trivial fit_fn runs and returns a valid C-index", {
data("cancer", package = "survival", envir = environment())
lung <- get("lung", envir = environment())
lung$status <- as.integer(lung$status == 2)
idx <- sample(seq_len(nrow(lung)), 40)      # tiny subset for speed
X <- as.matrix(df[, c("age", "sex", "ph.ecog", "ph.karno",
# Trivial "fit": return the training column means; predict: dot product with
# the test row. This is a sanity LOOCV, not a real model.
fit_fn <- function(X_tr, y_tr, hparam) colMeans(X_tr)
predict_fn <- function(model, X_te) as.numeric(X_te %*% model)
res <- loocv_cindex(X, y, fit_fn, predict_fn, seed = 42, verbose = FALSE)
expect_named(res, c("cindex", "risk", "n_folds", "n_failed",
expect_true(res$cindex >= 0 && res$cindex <= 1)
test_that("single-model registry entries fit and predict on lung", {
X <- as.matrix(lung[seq_len(45), c("age", "sex", "ph.ecog", "ph.karno",
for (algo_key in list_surv_algorithms()) {
hparam <- as.list(spec$grid(automlr_parameters())[1L, , drop = FALSE])
model <- spec$fit(X[1:40, , drop = FALSE], y[1:40], hparam)
risk <- spec$predict(model, X[41:45, , drop = FALSE])
test_that("model variants expand algorithm grids enough for >100 two-model combinations", {
counts <- count_surv_combinations(min_size = 2, max_size = 2)
count_surv_combinations(min_size = 2, max_size = 2,
expect_true(all(c("candidate_key", "algo_key", "hparam_label") %in% names(variants)))
test_that("evaluate_algorithm_loocv('lasso_cox') on lung: finite C-index", {
X <- as.matrix(lung[, c("age", "sex", "ph.ecog", "ph.karno",
res <- evaluate_algorithm_loocv("lasso_cox", X, y, params = params,
info = sprintf("lasso_cox LOOCV C-index was %s, errors: %d (%s)",
paste(utils::head(res$errors, 2), collapse = " | ")))
info = sprintf("lasso_cox LOOCV C-index = %.3f (<0.5 suggests sign flip)",
expect_true(res$n_failed <= ceiling(0.05 * res$n_folds),
info = sprintf("too many LOOCV failures: %d / %d",
test_that("fit_surv_ensemble builds a weighted single-model ensemble", {
X <- as.matrix(lung[seq_len(35), c("age", "sex", "ph.ecog", "ph.karno",
params <- automlr_parameters(algorithms = "lasso_cox", verbose = FALSE)
ens <- fit_surv_ensemble(X[1:30, , drop = FALSE], y[1:30],
params = params, algorithms = "lasso_cox",
risk <- predict(ens, X[31:35, , drop = FALSE])
report <- render_surv_report(ens, output_dir = report_dir, top_n = 5)
exported <- export_surv_results(ens, output_dir = export_dir,
expect_true(grepl("AutoMLR Survival Analysis Summary", summary_text,
expect_true(grepl("Explainability and Clinical Utility Outputs",
risk_scores <- utils::read.csv(file.path(export_dir, "tables", "risk_scores.csv"))
expect_true(all(c("sample_id", "time", "status", "risk_score", "risk_group") %in%
test_that("fit_surv_ensemble auto-uses automlr_input cohorts for stability", {
lung$cohort <- rep(c("A", "B"), length.out = nrow(lung))
lung <- lung[seq_len(36), c("sample_id", "cohort", "time", "status", "age", "sex",
prep <- prepare_cohort_input(lung, cohort = "cohort",
params <- automlr_parameters(algorithms = "lasso_cox",
ens <- fit_surv_ensemble(prep, params = params,
expected_sample_id <- unlist(lapply(prep$cohorts, `[[`, "sample_id"),
export_surv_results(ens, output_dir = export_dir, formats = "png", top_n = 5)
expect_true(grepl("Data Preparation Summary", data_summary, fixed = TRUE))
expect_true(grepl("Cohorts included: 2", data_summary, fixed = TRUE))
if (requireNamespace("timeROC", quietly = TRUE)) {
test_that("evaluate_surv_combinations ranks all-subset risk combinations", {
algo_label = c("Model 1", "Model 2", "Model 3"),
params = automlr_parameters(algorithms = c("m1", "m2", "m3"))
combos <- evaluate_surv_combinations(fake, y, max_size = 2,
test_that("survival automatic C-index threshold uses requested quantile", {
tab <- data.frame(candidate_key = c("m1", "m2", "m3"),
as.numeric(stats::quantile(tab$cindex, 0.75, names = FALSE)))
test_that("risk standardization preserves ordering with extreme outliers", {
y <- survival::Surv(seq(48, 1), rep(1, 48))
cindex_harrell(as.numeric(y[, "time"]), as.integer(y[, "status"]), standardized),
cindex_harrell(as.numeric(y[, "time"]), as.integer(y[, "status"]), risk)
test_that("evaluate_surv_combinations can report queue stability diagnostics", {
params = automlr_parameters(algorithms = c("m1", "m2"),
stability_groups = c("A", "A", "A", "B", "B", "B"),
test_that("evaluate_surv_combinations excludes same-base variants by default", {
algo_label = c("Model 1", "Model 1", "Model 2"),
params = automlr_parameters(algorithms = c("m1", "m2"))
combos <- evaluate_surv_combinations(fake, y, min_size = 2, max_size = 2,
test_that("fit_surv_ensemble can choose the best subset strategy", {
params <- automlr_parameters(algorithms = algos, verbose = FALSE)
strategy = "best_subset", max_models = 2,
test_that("extreme_surv_screen runs apparent top-N and seed search", {
lung <- lung[seq_len(42), c("cohort", "time", "status", "age", "sex",
exported_summary <- paste(readLines(exported$summary_report, warn = FALSE),
expect_true(grepl("Extreme Screening Summary", exported_summary, fixed = TRUE))
english_pos <- regexpr("Extreme Screening Summary", exported_summary,
summary_text <- summarize_extreme_screen_results(res, top_n = 2)
expect_true(grepl("Best validation row", summary_text, fixed = TRUE))
expect_true(grepl("Apparent Screen", summary_text, fixed = TRUE))
summary_text_en <- summarize_extreme_screen_results(res, top_n = 2,