Skip to contents

Convenience wrapper for elastic net regression using glmnet with cross-validation. Combines L1 and L2 penalties, balancing variable selection and grouping effects.

Usage

run_elastic_net(
  X,
  y,
  family = gaussian(),
  alpha = 0.5,
  standardize = TRUE,
  nfolds = 10
)

Arguments

X

Design matrix of predictors (n × p).

y

Response vector or survival object.

family

Response family. Can be gaussian(), binomial(), poisson(), Gamma(), or "cox" for Cox regression.

alpha

Elastic net mixing parameter. Default 0.5 (equal L1/L2 weighting).

standardize

Logical. Should variables be standardized? Default TRUE.

nfolds

Number of cross-validation folds. Default 10.

Value

A list containing the same components as run_glmnet.

Details

Elastic net regression combines the variable selection capability of LASSO with the grouping effect of ridge regression. When predictors are correlated, elastic net tends to select groups of correlated variables rather than arbitrarily choosing one from each group.

See also

Examples

if (FALSE) { # \dontrun{
# Simulate correlated predictors
set.seed(123)
n <- 100; p <- 50
X <- matrix(rnorm(n * p), n, p)
# Add correlation between first 5 variables
X[,2:5] <- X[,2:5] + 0.8 * X[,1]
y <- X[,1:3] %*% c(1, -1, 0.5) + rnorm(n)

# Run elastic net
enet_result <- run_elastic_net(X, y, alpha = 0.5)
print(enet_result$selected)
} # }