glmnet_with_cv {SVEMnet}R Documentation

Fit a glmnet Model with Cross-Validation

Description

A wrapper function for cv.glmnet that takes input arguments in a manner similar to SVEMnet. This function searches over multiple alpha values by running cv.glmnet() for each provided alpha, and then selects the combination of alpha and lambda with the best cross-validation performance.

Usage

glmnet_with_cv(
  formula,
  data,
  glmnet_alpha = c(0, 0.5, 1),
  standardize = TRUE,
  nfolds = 10,
  ...
)

Arguments

formula

A formula specifying the model to be fitted.

data

A data frame containing the variables in the model.

glmnet_alpha

Elastic Net mixing parameter(s) (default is c(0, 0.5, 1)). If multiple values are provided, cv.glmnet is run for each alpha, and the model with the lowest cross-validation error is selected.

standardize

Logical flag passed to glmnet. If TRUE (default), each variable is standardized before model fitting.

nfolds

Number of cross-validation folds (default is 10).

...

Additional arguments passed to cv.glmnet.

Details

This function uses cv.glmnet to fit a generalized linear model with elastic net regularization, performing k-fold cross-validation to select the regularization parameter lambda. If multiple alpha values are provided, it selects the best-performing alpha-lambda pair based on the minimal cross-validation error.

After fitting, the function calculates a debiasing linear model (if possible). This is done by regressing the actual responses on the fitted values obtained from the selected model. The resulting linear model is stored in debias_fit.

Value

A list containing:

References

Friedman, J., Hastie, T., & Tibshirani, R. (2010). Regularization Paths for Generalized Linear Models via Coordinate Descent. Journal of Statistical Software, 33(1), 1-22. doi:10.18637/jss.v033.i01

See Also

glmnet, cv.glmnet, SVEMnet

Examples

set.seed(0)
n <- 50
X1 <- runif(n)
X2 <- runif(n)
y <- 1 + 2*X1 + 3*X2 + rnorm(n)
data <- data.frame(y, X1, X2)

model_cv <- glmnet_with_cv(y ~ X1 + X2, data = data, glmnet_alpha = c(0,0.5,1))
predictions <- predict_cv(model_cv, data)


[Package SVEMnet version 1.3.0 Index]