What Alpha and Lambda Control
In glmnet, alpha and lambda control different aspects of regularization. Alpha sets the type of penalty: it determines the balance between the lasso’s absolute-value penalty and the ridge penalty. Lambda sets the overall strength of that penalty. A fitted coefficient therefore depends on both values, as well as on the data, the model family, and preprocessing such as predictor scaling.
For Gaussian regression, glmnet uses a penalized least-squares objective. In the expression below, \(y_i\) is response \(i\), \(x_{ij}\) is predictor \(j\) for observation \(i\), \(\beta_0\) is the intercept, and \(\beta_j\) is the coefficient for predictor \(j\). The intercept is not penalized. This objective uses glmnet’s Gaussian loss scaling; changing the loss scaling changes the numerical scale of lambda.
The lasso can set coefficients exactly to zero, while ridge generally shrinks coefficients without setting them exactly to zero. Elastic net combines these behaviors; for \(0<\alpha<1\), it includes both an absolute-value and a squared-coefficient penalty. Alpha is not the percentage of predictors retained, and lambda is not a significance threshold. Neither parameter alone tells us that a predictor is important.
Why the Coefficient Formula Has a Threshold
A simple Gaussian setting makes the roles of the parameters visible. Assume the response and predictors are centered, each predictor has mean square one, and distinct predictors are orthogonal, so their sample cross-products divided by \(n\) are zero. Define \(z_j=(1/n)\sum_i x_{ij}y_i\), the unpenalized least-squares coefficient for predictor \(j\) under these assumptions. With no intercept needed after centering, the objective separates into one term per coefficient.
For one predictor, after dropping terms that do not depend on \(\beta\), the part of the objective involving its coefficient is:
To see why a threshold occurs, consider a positive coefficient. Differentiating the objective for \(\beta>0\) gives \(\beta-z+\lambda\alpha+\lambda(1-\alpha)\beta=0\). Hence a positive solution is possible only when \(z>\lambda\alpha\), and then its value is \((z-\lambda\alpha)/(1+\lambda(1-\alpha))\). For a negative coefficient, the derivative of \(|\beta|\) is \(-1\), giving a negative solution only when \(z<-\lambda\alpha\). If \(-\lambda\alpha\leq z\leq\lambda\alpha\), the minimum is at zero: moving away from zero cannot overcome the penalty. Combining these cases gives the soft-threshold formula.
This formula is a teaching result for the stated orthogonal, standardized Gaussian setup, not a general closed-form solution for glmnet. With correlated predictors, the coefficients are coupled and glmnet solves the full penalized optimization problem. With other model families, the likelihood contribution differs. In practical fits, also check the response family, standardization, and whether reported coefficients have been returned on the original predictor scale.
Worked Example: Comparing the Endpoints and a Mixture
Suppose a centered Gaussian regression has two orthogonal standardized predictors, with \(z_1=0.90\) and \(z_2=0.80\). Calculate the coefficients when \(\lambda=0.40\) for \(\alpha=0.50\), then compare them with the lasso and ridge endpoints. Use the orthogonal-predictor formula and round only final coefficients to four decimal places.
Method. Apply the soft-threshold formula separately to each predictor. For the elastic net fit, the threshold is \(\lambda\alpha=(0.40)(0.50)=0.20\), and the denominator is \(1+\lambda(1-\alpha)=1+(0.40)(0.50)=1.20\).
For predictor 1, the numerator is \(\max(0.90-0.20,0)=0.70\). Thus \(\widehat{\beta}_1=0.70/1.20=0.583333\ldots\), or 0.5833. For predictor 2, the numerator is \(\max(0.80-0.20,0)=0.60\). Thus \(\widehat{\beta}_2=0.60/1.20=0.500000\), or 0.5000.
At the lasso endpoint, \(\alpha=1\), the threshold is \(0.40\) and the denominator is 1. The coefficients are \(0.90-0.40=0.5000\) and \(0.80-0.40=0.4000\). At the ridge endpoint, \(\alpha=0\), the threshold is zero and the denominator is \(1+0.40=1.40\). The coefficients are \(0.90/1.40=0.642857\ldots\), or 0.6429, and \(0.80/1.40=0.571428\ldots\), or 0.5714.
Check. The lasso coefficients are reduced by a fixed threshold when they remain nonzero; ridge divides both unpenalized coefficients by the same factor here. The elastic net values fall between these endpoint values for these positive inputs. The common mistake avoided is applying the lasso threshold but forgetting the elastic net denominator.
Reading a Fitted glmnet Model
A glmnet fit is usually evaluated along a sequence of lambda values for a chosen alpha. A coefficient path records how the fitted coefficients change across that sequence. At a fixed lambda, the coefficients describe the model fitted with that alpha and lambda, subject to the specified data and preprocessing. They do not by themselves establish how useful a predictor is in other samples or under a different modeling choice.
In R, a basic Gaussian fit with a chosen mixture might be written as fit <- glmnet(x, y, family = "gaussian", alpha = 0.5). Coefficients at a supplied lambda can be requested with coef(fit, s = 0.2). The requested value should correspond to the fit’s lambda path or be handled according to the function’s interpolation behavior. Check the returned object and coefficient names rather than assuming every coefficient is nonzero or that the display order matches a preferred interpretation.
With the default predictor standardization, glmnet standardizes predictors for fitting and reports coefficients on the original predictor scale. If standardization is changed, or preprocessing is done separately, coefficient magnitudes are not directly comparable without accounting for the scales. For factors, the model matrix contains indicator columns; the printed coefficient for one indicator is not automatically a single overall measure of that factor’s importance.
Worked Example: Interpreting Coefficients at a Stated Lambda
A hypothetical analyst fits a Gaussian glmnet model with \(\alpha=0.60\). At \(\lambda=0.25\), the returned coefficient table has intercept 4.10, coefficient 0.00 for “inspection age,” coefficient \(-0.32\) for “prior service count,” and coefficient 0.18 for “site type B.” Interpret the table for a one-unit increase in each numeric predictor and for the displayed indicator, holding the other model-matrix columns fixed. Assume the predictors are presented on their original scales.
Method. Read each number as a coefficient in this particular fitted model, at the stated alpha and lambda. In a Gaussian model with an identity link, the fitted mean response changes by the coefficient times the predictor change, with other predictors fixed.
The coefficient for inspection age is 0.00, so its fitted contribution is zero at this displayed precision and penalty value. This does not prove that inspection age has no association in the population or that it would be zero under another fit. The coefficient for prior service count is \(-0.32\): increasing that count by one unit changes the fitted mean response by \(-0.32\), conditional on the other model-matrix columns. The coefficient 0.18 for site type B is the fitted difference associated with that indicator being one rather than zero, with the reference coding and other columns held fixed.
Check. These are conditional model interpretations, not causal effects or universal importance rankings. The zero coefficient indicates the fitted penalized solution at this setting; it is not evidence by itself that the predictor is irrelevant. The common mistake avoided is interpreting a coefficient table as a ranking independent of alpha, lambda, units, coding, and the other predictors.
Worked Example: A Negative Coefficient and the Sign Trap
Use the orthogonal standardized Gaussian setup with \(z_1=0.90\), \(z_2=-0.40\), \(\alpha=0.50\), and \(\lambda=0.40\). Calculate both coefficients, showing how the negative sign is handled. Round only final values to four decimal places.
Method. The threshold is \(0.40(0.50)=0.20\), and the denominator is \(1+0.40(0.50)=1.20\). For predictor 1, the thresholded numerator is \(0.90-0.20=0.70\), so \(\widehat{\beta}_1=0.70/1.20=0.5833\).
For predictor 2, \(|z_2|=0.40\), so the numerator’s magnitude after thresholding is \(0.40-0.20=0.20\). Its sign remains negative. Therefore \(\widehat{\beta}_2=-0.20/1.20=-0.166666\ldots\), or \(-0.1667\).
Check. The penalty reduces the magnitude of the negative unpenalized coefficient without reversing its sign. A common sign trap is to negate an expression that already has the negative sign accounted for, producing an incorrect positive value such as \(+0.5000\). The correct calculation uses \(\operatorname{sign}(z_2)=-1\) and the thresholded magnitude \(0.20\), giving \(-0.1667\).
What a Lambda Change Does—and Does Not—Mean
For a fixed alpha, increasing lambda strengthens the penalty in the objective. In the orthogonal formula, increasing lambda raises the lasso threshold \(\lambda\alpha\), and also changes the elastic net denominator when \(\alpha<1\). Coefficients can therefore shrink, and for a lasso-containing penalty some can become exactly zero. In a general correlated design, individual coefficient paths need not follow the simple scalar formula, so use the fitted path or coefficient table rather than extrapolating from the orthogonal case.
The numerical lambda values should not be compared as if they were universal. They depend on the response and predictor scales, loss definition, sample, and model family. A value such as 0.25 is not intrinsically “small” or “large.” A reported fit should identify alpha and the lambda used, and relevant preprocessing choices should be made clear.
A lambda selected for predictive performance is a modeling choice, not proof that retained variables are more important than omitted ones. Likewise, alpha specifies the penalty mixture; choosing an alpha does not assign relative scientific importance to predictors. Interpret coefficients in context, including their units, coding, conditional nature, and the uncertainty inherent in the model and data.
Check Your Understanding
For calculation questions, use the orthogonal, standardized Gaussian formula unless the problem states otherwise. Round calculated coefficients to four decimal places.
- For one predictor, \(z=0.50\), \(\alpha=0.25\), and \(\lambda=0.80\). Calculate the fitted coefficient. (Answer: 0.1875)
- For one predictor, \(z=-0.20\), \(\alpha=1\), and \(\lambda=0.30\). Calculate the fitted coefficient and identify the penalty type. (Answer: 0.0000; lasso)
- For one predictor, \(z=0.60\), \(\alpha=0.50\), and \(\lambda=0.20\). Calculate the fitted coefficient. (Answer: 0.4545)
- For two orthogonal predictors with \(z_1=0.40\) and \(z_2=-0.60\), calculate both coefficients when \(\alpha=0\) and \(\lambda=0.50\). (Answer: \(\widehat{\beta}_1=0.2667,\ \widehat{\beta}_2=-0.4000\))
- A predictor has \(z=0.24\), with \(\alpha=0.60\). At what smallest lambda does its lasso-thresholded coefficient become zero in this orthogonal setup? (Answer: \(\lambda=0.4000\); it is zero when \(\lambda\geq0.4000\))