`%||%` <- function(x, y) if (is.null(x)) y else x test_that("stabpath returns a coherent matrix path", { skip_if_not_installed("glmnet") set.seed(126) n <- 80; p <- 12 x <- matrix(rnorm(n * p), n, p) beta <- c(2, -2, 1.5, rep(0, p-3)) pr <- 1/(1+exp(-scale(drop(x %*% beta)))) y <- factor(rbinom(n, 1, pr), levels = c(0,1)) sp <- c060::stabpath(y = y, x = x, steps = 20L, weakness = 1, family = "binomial") expect_s3_class(sp, "stabpath") expect_true(is.matrix(sp$stabpath)) expect_equal(nrow(sp$stabpath), p) # rows are features expect_true(ncol(sp$stabpath) >= 1) # columns ~ lambda grid expect_true(all(is.finite(sp$stabpath))) }) test_that("stabsel selects variables at or above threshold (may be empty)", { skip_if_not_installed("glmnet") set.seed(127) n <- 80; p <- 10 x <- matrix(rnorm(n * p), n, p) eta <- drop(scale(x[,1]*2 - x[,2])) y <- factor(rbinom(n, 1, 1/(1+exp(-eta))), levels = c(0,1)) sp <- stabpath(y = y, x = x, steps = 20L, weakness = 1, family = "binomial") ss <- stabsel(sp, error = 0.05, type = "pfer", pi_thr = 0.6) expect_true(is.list(ss)) S <- ss$stable %||% integer(0) if (length(S)) { ph <- sp$stabpath[, ss$lpos, drop = TRUE] expect_true(all(ph[S] >= 0.6 - 1e-8)) } else { succeed("No variables crossed threshold in this tiny run (acceptable)") } })