cv.srlars: Cross-Validated Selection of 'max_share' for FSCRE...

View source: R/cv.srlars.R

cv.srlarsR Documentation

Cross-Validated Selection of max_share for FSCRE (cv.srlars)

Description

cv.srlars chooses the max_share argument of srlars by cross-validation and returns the FSCRE ensemble refit on the full data at the cross-validated optimum. The internal cross-validation used by the competitive arbiter inside srlars (controlled by cv_folds) is unrelated and untouched by this function: it decides which variable each sub-model proposes next. cv.srlars adds a separate, outer cross-validation loop whose only job is to pick the best max_share value from share_grid.

To keep this efficient, the expensive cellwise-robust preprocessing stage (DDC imputation, wrapping, and robust correlation estimation) does not depend on max_share, so it is computed only once per outer fold and reused across every candidate value in share_grid for that fold, rather than being recomputed for every (fold, candidate) pair.

Usage

cv.srlars(
  x,
  y,
  n_models = 5,
  share_grid = NULL,
  outer_folds = 5,
  tolerance = 1e-08,
  n_min = NULL,
  max_predictors = NULL,
  x_preprocess = c("ddc", "none"),
  y_preprocess = c("wrap", "robust_z", "none"),
  cor_estimator = c("wrap", "pearson"),
  cv_preprocess = c("global", "foldwise"),
  cv_fit = c("huber", "ls"),
  cv_loss = c("huber", "trimmed", "mse"),
  cv_folds = 5,
  compute_coef = TRUE
)

Arguments

x

Design matrix (n x p).

y

Response vector (n x 1).

n_models

Number of models in the ensemble (K). Default is 5.

share_grid

Integer vector of candidate max_share values to evaluate. Default is 1:n_models.

outer_folds

Integer. Number of outer cross-validation folds used to select max_share. Default is 5.

tolerance

Relative improvement tolerance for stopping (tau). Default is 1e-8.

n_min

Integer or NULL. Minimum number of variables each sub-model is guaranteed (subject to availability), passed through unchanged to every candidate fit and the final refit – cv.srlars does not tune n_min, only max_share. Default is NULL (no floor). See srlars.

max_predictors

Maximum total number of variables to select across all models. Default is n * n_models.

x_preprocess

Character. "ddc" (default) for cellwise cleaning, or "none".

y_preprocess

Character. "wrap" (default) for univariate robustification, "robust_z", or "none".

cor_estimator

Character. "wrap" (default) for robust PSD correlation, or "pearson".

cv_preprocess

Character. "global" (default) or "foldwise" (to prevent data leakage).

cv_fit

Character. "huber" (default) or "ls" for the inner arbiter fitting method.

cv_loss

Character. "huber" (default), "trimmed", or "mse" for arbiter scoring and for scoring max_share candidates in the outer loop.

cv_folds

Integer. Number of internal (arbiter) cross-validation folds. Default is 5.

compute_coef

Logical. If TRUE, fits the final robust MM-models. Default is TRUE.

Value

An object of class c("cv.srlars", "srlars"): the srlars fit at the cross-validated optimal max_share, with three extra components:

max_share

The cross-validated optimal value.

share_grid

The candidate values that were evaluated.

cv_errors

The mean out-of-fold error for each value in share_grid.

Because no coef.cv.srlars or predict.cv.srlars methods are defined, calling coef() or predict() on the result dispatches to coef.srlars / predict.srlars and operates on this optimal fit directly.

Author(s)

Anthony-Alexander Christidis, anthony.christidis@stat.ubc.ca

See Also

srlars, coef.srlars, predict.srlars

Examples

# Required libraries
library(mvnfast)
library(cellWise)
library(robustbase)

# Simulation parameters
n <- 50
p <- 30
rho.within <- 0.8
rho.between <- 0.2
p.active <- 10
group.size <- 5
snr <- 3

# Setting the seed
set.seed(0)

# Block correlation structure
sigma.mat <- matrix(0, p, p)
sigma.mat[1:p.active, 1:p.active] <- rho.between
for(group in 0:(p.active/group.size - 1))
  sigma.mat[(group*group.size+1):(group*group.size+group.size),
  (group*group.size+1):(group*group.size+group.size)] <- rho.within
diag(sigma.mat) <- 1

# Simulation of beta vector
true.beta <- c(runif(p.active, 0, 5)*(-1)^rbinom(p.active, 1, 0.7), rep(0, p - p.active))

# Setting the SD of the variance
sigma <- as.numeric(sqrt(t(true.beta) %*% sigma.mat %*% true.beta)/sqrt(snr))

# Simulation of uncontaminated data
x <- mvnfast::rmvn(n, mu = rep(0, p), sigma = sigma.mat)
colnames(x) <- paste0("V", 1:p)
y <- x %*% true.beta + rnorm(n, 0, sigma)

# Cross-validated choice of max_share
cv_fit <- cv.srlars(x, y,
                    n_models = 3,
                    outer_folds = 3,
                    tolerance = 1e-4)

# Cross-validated optimal max_share
print(cv_fit$max_share)

# coef() and predict() dispatch to the srlars methods automatically
cv_coefs <- coef(cv_fit)


srlars documentation built on Sept. 23, 2026, 5:10 p.m.