Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In R, glmnet fits penalized regression models across a path of lambda values. Choose alpha to set the penalty mix—0 for ridge, 1 for lasso, or a value between them for elastic net—and use validation that matches your outcome and goal to select a model. Cross-validation does not choose alpha for you.

What penalized regression does

Penalized regression estimates model coefficients while adding a penalty that shrinks them. This helps control model complexity; it does not, by itself, establish that a model predicts well on new data or that a selected predictor has a causal effect.

The R package glmnet fits penalized maximum-likelihood models and calculates a regularization path over lambda values. It accepts a predictor matrix, including sparse matrices, and standardizes predictors by default (standardize=TRUE). See the glmnet function reference for fitting inputs and behavior.

Ridge, lasso, and elastic net: what does alpha change?

alpha sets the mixture of L1 and L2 penalties. As the glmnet vignette puts it: “The elastic net penalty is controlled by α, and bridges the gap between lasso regression (α = 1) and ridge regression (α = 0).”

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Choice alpha Penalty behavior Useful distinction
Ridge 0 L2-only; shrinks coefficients. Does not use the L1 component that can set coefficients to zero.
Lasso 1 L1-only; can set some coefficients to zero. Can produce a sparse fit, but a nonzero coefficient is not proof of causal importance.
Elastic net Between 0 and 1 Combines L1 and L2 components. Lets you choose an intermediate penalty mix; the best value depends on the task and data.

lambda is a separate choice: it controls regularization strength along the path. In practice, select a penalty type or candidate set of alpha values, then tune lambda against an appropriate validation measure. The glmnet documentation index lists the package’s fitting and selection functions.

Which response types can glmnet model?

The package documentation lists Gaussian, binomial, multinomial, Poisson, Cox, and multiple-response Gaussian models. Its index also describes grouped multinomial models. The appropriate family depends on how the response is measured and what question the model is meant to answer; consult the CRAN glmnet package index for package scope.

How do you choose alpha and lambda with cv.glmnet?

cv.glmnet runs k-fold cross-validation and reports information for choosing lambda. It requires you to supply alpha; it does not search across alpha values. If you want to compare ridge, lasso, and elastic net candidates, pass a common precomputed foldid to each call so the comparisons use the same fold assignments.

  1. Choose the response family and candidate penalty mixes. Set family to match the response, and set one or more explicit alpha values.
  2. Set a fold strategy. Create a foldid vector if you need reproducible folds or a fair comparison across alpha values. By default, fold assignment is random, so separate runs can produce different results.
  3. Choose a validation measure that fits the task. The default depends on family: squared error (also called MSE) for Gaussian, deviance for logistic and Poisson, and partial likelihood for Cox models. Documented alternatives include classification error for binomial and multinomial models, AUC for two-class logistic models, MSE or MAE for eligible models, and Harrell’s concordance for Cox. Check the current reference manual for which measures are available for your specific family.
  4. Fit and compare candidates. Run cv.glmnet for each chosen alpha using the same folds. Compare validation curves and relevant model characteristics rather than treating any one alpha as universally best.
  5. State the lambda rule you use. lambda.min is the value associated with the minimum cross-validation error. lambda.1se is the largest lambda whose error is within one standard error of the minimum; it favors stronger regularization among values meeting that criterion. Neither rule is best in every setting, so explain the trade-off and the rule used.

The function documentation suggests repeating cross-validation and averaging error curves as one way to reduce variability from random fold assignment. If cross-validation is used both to select a model and to make a final performance claim, account for that selection; an appropriate held-out or nested assessment may be needed for an unbiased evaluation, depending on the study design.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to report a penalized regression analysis

A selected lambda alone is not enough for someone to understand or reproduce a fit. Report the choices that determine what was fit and how it was evaluated:

  • Response family and the outcome being modeled.
  • alpha, including how candidate values were compared if more than one was tried.
  • Validation measure and why it matches the prediction task.
  • Fold strategy, including whether folds were fixed, randomized, or repeated.
  • Selected lambda rule, such as lambda.min or lambda.1se.
  • Predictor preprocessing, including standardization settings and any additional transformations.
  • Performance estimate and how it was obtained, distinguishing tuning results from a separate final assessment where applicable.

Penalized fits can support prediction or exploratory screening, but coefficient shrinkage and selection do not automatically provide confirmatory inference. Use an inferential method suited to that purpose if the goal is to make inferential claims.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.