Why Ridge Penalty Conventions Matter
A ridge fit depends on both the data and the penalty strength. The difficulty when comparing software is that packages can express the fitting objective on different scales. One implementation may penalize the residual sum of squares, another may penalize the mean squared error, and another may include a factor of one-half in both terms. These are not necessarily different statistical methods: multiplying an entire objective by a positive constant does not change its minimizer. But changing only one term does change the relative strength of the penalty.
The practical consequence is important: the same numerical value of lambda can represent different amounts of shrinkage under different objective conventions. Before comparing fitted coefficients or a selected tuning parameter across software, identify the exact objective and convert lambda values when necessary.
RSS convention: \(\operatorname{RSS}(\beta)+\lambda_{\mathrm{RSS}}\|\beta\|_2^2\).
MSE convention: \(\operatorname{RSS}(\beta)/n+\lambda_{\mathrm{MSE}}\|\beta\|_2^2\).
glmnet Gaussian convention for ridge: \(\operatorname{RSS}(\beta)/(2n)+\lambda_{\mathrm{glmnet}}\|\beta\|_2^2/2\), corresponding to \(\alpha=0\).
Here \(\|\beta\|_2^2\) means the sum of squared penalized coefficients. A common intercept convention is to estimate the intercept but exclude it from this sum. The conversions below assume that all three objectives use the same observations, weights, predictor representation, response scale, and penalized coefficients. If any of those differ, converting lambda alone may not make the fits equivalent.
The Conversion Between Lambda Values
The conversion follows by putting the objectives on a common scale. Multiplying an objective by a positive constant leaves its minimizer unchanged, because every candidate fit is then ranked by the same relative objective values.
The first line divides the entire RSS objective by \(n\). The third line multiplies the glmnet objective by two. Matching the penalty coefficients in the resulting MSE-scale objectives gives the conversions.
This is a conversion between objective normalizations, not a universal rule that a particular package always uses one convention. For example, the stated glmnet objective applies to its Gaussian model with ridge selected by \(\alpha=0\). Its default predictor standardization and other fitting settings can also affect a comparison. Check the documented objective and settings rather than relying on the package name or on a lambda value by itself.
Worked Example: Converting an RSS Penalty to an MSE Penalty
A hypothetical portfolio study uses four observations and one centered predictor. The sufficient statistics are \(x^\mathsf{T}x=10\) and \(x^\mathsf{T}y=20\). The fitted model has no intercept because the variables are centered. Find the ridge coefficient under the RSS objective with \(\lambda_{\mathrm{RSS}}=10\), and find the matching MSE-scale lambda.
Method. For this one-predictor model, the residual sum of squares is \((y-x\beta)^\mathsf{T}(y-x\beta)\). Expanding and adding the ridge penalty gives $$ \operatorname{RSS}(\beta)+\lambda_{\mathrm{RSS}}\beta^2 =y^\mathsf{T}y-2\beta x^\mathsf{T}y+\beta^2 x^\mathsf{T}x +\lambda_{\mathrm{RSS}}\beta^2. $$
The terms depending on \(\beta\) are \(-2(20)\beta+(10+10)\beta^2\). Differentiating and setting the derivative to zero gives \(-40+40\beta=0\), so \(\hat\beta=1\). The second derivative is \(2(10+10)=40>0\), confirming this is the minimum.
There are \(n=4\) observations, so the matching MSE penalty is \(\lambda_{\mathrm{MSE}}=\lambda_{\mathrm{RSS}}/n=10/4=2.5\). Directly minimizing the MSE objective gives $$ \frac{\operatorname{RSS}(\beta)}{4}+2.5\beta^2, \qquad \frac{d}{d\beta}=\frac{2(10\beta-20)}{4}+5\beta =10\beta-10. $$
Setting this derivative to zero again gives \(\hat\beta=1\). The two objectives agree on the fitted coefficient. Common mistake avoided: using 10 as the MSE-scale lambda without dividing by the sample size.
Derivation Through the Ridge Normal Equations
The one-predictor calculation illustrates the conversion, but the same result holds for multiple predictors. Suppose the predictors and response have been centered so that the intercept is handled separately. Under the RSS convention, the objective is \((y-X\beta)^\mathsf{T}(y-X\beta)+\lambda_{\mathrm{RSS}}\beta^\mathsf{T}\beta\). Differentiating with respect to \(\beta\) yields
Under the MSE convention, differentiation instead gives
The normal equations are identical when \(\lambda_{\mathrm{RSS}}=n\lambda_{\mathrm{MSE}}\). Replacing \(\lambda_{\mathrm{MSE}}\) by \(\lambda_{\mathrm{glmnet}}\) gives the same equivalence for the stated glmnet objective. This derivation assumes ordinary least squares residuals and a penalty on the same coefficient vector in both formulations; a different weighting scheme or penalized-intercept convention requires comparing the objectives as actually implemented.
Worked Example: Same Numerical Lambda, Different Fits
A hypothetical insurer’s analysis has \(n=8\) observations and one centered predictor, with \(x^\mathsf{T}x=24\) and \(x^\mathsf{T}y=48\). Compare a fit using \(\lambda_{\mathrm{RSS}}=12\) with a fit using \(\lambda_{\mathrm{glmnet}}=12\). Then calculate the glmnet lambda that matches the RSS fit.
Method. The RSS-objective ridge estimate is $$ \hat\beta_{\mathrm{RSS}} =\frac{x^\mathsf{T}y}{x^\mathsf{T}x+\lambda_{\mathrm{RSS}}} =\frac{48}{24+12} =\frac{48}{36} =\frac{4}{3}. $$
For the stated glmnet objective, the normal equation has \(n\lambda_{\mathrm{glmnet}}\) added to \(x^\mathsf{T}x\). Using the same numerical lambda, 12, gives $$ \hat\beta_{\mathrm{glmnet}} =\frac{48}{24+8(12)} =\frac{48}{120} =0.4. $$
The different coefficients do not indicate a software error: the two numerical values 12 apply to differently normalized objectives. To match the RSS fit, set \(\lambda_{\mathrm{glmnet}}=\lambda_{\mathrm{RSS}}/n=12/8=1.5\). Then $$ \hat\beta_{\mathrm{glmnet}} =\frac{48}{24+8(1.5)} =\frac{48}{36} =\frac{4}{3}. $$
Check. The converted lambda reproduces the RSS coefficient, while the unconverted lambda produces a smaller coefficient. Common mistake avoided: concluding that two implementations disagree statistically before checking how each scales its loss term.
Multiple Predictors and Software Comparisons
The sample-size conversion is not limited to a single coefficient. Suppose there are two centered, mutually orthogonal predictors, with \(x_1^\mathsf{T}x_1=10\), \(x_2^\mathsf{T}x_2=20\), \(x_1^\mathsf{T}x_2=0\), and response cross-products \(x_1^\mathsf{T}y=30\) and \(x_2^\mathsf{T}y=40\). With an RSS penalty of 5, the ridge normal equations separate into two scalar equations: $$ (10+5)\hat\beta_1=30,\qquad (20+5)\hat\beta_2=40. $$ Thus \(\hat\beta_1=2\) and \(\hat\beta_2=1.6\). If there are five observations, the equivalent glmnet lambda is \(5/5=1\). Its equations are \((10+5(1))\hat\beta_1=30\) and \((20+5(1))\hat\beta_2=40\), giving the same coefficients. The common conversion applies to the whole penalty, not separately to each coefficient.
For a practical comparison, first write each package’s objective in a common form. Then check that the observations and coefficient definitions match. In particular, glmnet normally standardizes predictors by default, and its fitting procedure has an intercept convention. A comparison with software using unstandardized predictors may not be explained by the \(n\)-factor alone. The objective conversion isolates the loss-normalization issue; it does not erase differences in preprocessing or model specification.
A useful comparison table is:
| Objective form | Penalty coefficient for an equivalent RSS lambda | Matching lambda |
|---|---|---|
| \(\operatorname{RSS}+\lambda_{\mathrm{RSS}}\|\beta\|_2^2\) | \(\lambda_{\mathrm{RSS}}\) | \(\lambda_{\mathrm{RSS}}\) |
| \(\operatorname{RSS}/n+\lambda_{\mathrm{MSE}}\|\beta\|_2^2\) | \(n\lambda_{\mathrm{MSE}}\), when put on the RSS scale | \(\lambda_{\mathrm{MSE}}=\lambda_{\mathrm{RSS}}/n\) |
| \(\operatorname{RSS}/(2n)+\lambda_{\mathrm{glmnet}}\|\beta\|_2^2/2\) | \(n\lambda_{\mathrm{glmnet}}\), when put on the RSS scale | \(\lambda_{\mathrm{glmnet}}=\lambda_{\mathrm{RSS}}/n\) |
The factors of one-half in the glmnet form cancel because they multiply both the loss and penalty. By contrast, dividing only the loss by \(n\) while leaving the penalty unchanged changes the relative penalty strength. That distinction is the core of the conversion.
Check Your Understanding
For each problem, identify the objective convention before comparing coefficients.
- A centered one-predictor model has \(n=6\), \(x^\mathsf{T}x=18\), and \(x^\mathsf{T}y=36\). Under the RSS convention, \(\lambda_{\mathrm{RSS}}=6\). Find the coefficient and the matching MSE lambda. (Answer: \(\hat\beta=1.5\); \(\lambda_{\mathrm{MSE}}=1\))
- A study has \(n=10\). What RSS-scale lambda matches a glmnet Gaussian ridge fit with \(\lambda_{\mathrm{glmnet}}=0.4\), assuming the same coefficient scale and fitting setup? (Answer: \(\lambda_{\mathrm{RSS}}=10(0.4)=4\))
- A software objective is \(\operatorname{RSS}/n+\lambda\|\beta\|_2^2\), with \(n=5\) and \(\lambda=2\). What RSS-scale lambda gives the same fit? (Answer: \(\lambda_{\mathrm{RSS}}=5(2)=10\))
- For \(n=8\), an RSS-objective fit uses \(\lambda_{\mathrm{RSS}}=10\). What glmnet lambda matches it, and why would using 10 in glmnet not be an equivalent comparison? (Answer: \(\lambda_{\mathrm{glmnet}}=10/8=1.25\); using 10 adds an RSS-scale penalty of \(8(10)=80\), not 10.)
- One implementation uses \(\operatorname{RSS}/n+\lambda\|\beta\|_2^2\); another uses \(\operatorname{RSS}/(2n)+\lambda\|\beta\|_2^2/2\). With identical data, coefficient definitions, and settings, must their same numerical lambda values produce the same fit? (Answer: Yes. Multiplying the second objective by 2 gives the first objective exactly.)