Tutorials › Exam PA - Predictive Analytics › Lambda as a Shrinkage Control

Exam PA · Penalties and Ridge Regression · Tutorial 419 of 966

Lambda as a Shrinkage Control

See how changing lambda changes ridge coefficients and fitted values, and learn when shrinkage can be interpreted directly.

Intermediate 10 min read

What You'll Learn

  • Interpret lambda relative to the loss and penalty in a stated ridge objective
  • Calculate ridge coefficients for orthogonal standardized predictors
  • Compare fitted coefficients and predictions at small, moderate, and large penalty values
  • Explain shrinkage using the eigen-directions of the predictor cross-product matrix
  • Distinguish shrinking coefficient magnitude from guaranteeing that every coefficient decreases
  • Identify why lambda values cannot be compared without checking the objective and predictor scaling

Lambda Controls the Strength of Ridge Shrinkage

Ridge regression adds a penalty on coefficient size to the usual least-squares fitting criterion. The parameter \(\lambda\) controls how strongly that penalty influences the fit: for a fixed data set and a fixed objective, increasing \(\lambda\) gives the fitting procedure a stronger reason to prefer smaller coefficients. The effect is continuous, not a switch that either keeps or removes a predictor.

To make calculations precise, this tutorial uses centered responses and predictors, with an unpenalized intercept handled separately. Consider the ridge objective

$$ Q_\lambda(\boldsymbol{\beta}) = \frac{1}{2n}\sum_{i=1}^n \left(y_i-\sum_{j=1}^p x_{ij}\beta_j\right)^2 +\frac{\lambda}{2}\sum_{j=1}^p\beta_j^2, \qquad \lambda\geq 0. $$

Here \(n\) is the number of observations, \(p\) is the number of predictors, and \(\boldsymbol{\beta}\) is the vector of predictor coefficients. The first term measures fit by residual sum of squares; the second penalizes large coefficients. The intercept is not included in the penalty. The factor \(1/(2n)\) and the factor \(1/2\) are part of the stated convention: the numerical meaning of a particular \(\lambda\) depends on the objective used.

Definition: In the stated ridge objective, \(\lambda\) is a nonnegative penalty parameter. Holding the data, predictor scaling, and objective convention fixed, a larger \(\lambda\) places more weight on keeping the coefficient vector small relative to reducing residual error. It does not mean that each coefficient is multiplied by \(1-\lambda\), nor does it specify a universal percentage of shrinkage.

What Changes as Lambda Changes?

For a simple, interpretable case, suppose the predictors have been centered and standardized so that each has mean zero and mean square one, and suppose distinct predictors are orthogonal. In matrix notation, these conditions give \(X^\mathsf{T}X/n=I\), where \(X\) is the design matrix and \(I\) is the identity matrix. Define \(b=X^\mathsf{T}y/n\). Under these conditions, the ordinary least-squares coefficient vector is \(b\), and ridge gives

$$ \widehat{\boldsymbol{\beta}}_\lambda = \frac{b}{1+\lambda}. $$

Thus, in this special case, every coefficient is scaled by the same factor \(1/(1+\lambda)\). For example, \(\lambda=0.1\) gives a factor of about \(0.9091\), while \(\lambda=1\) gives a factor of \(0.5\). These factors follow from the stated objective and orthogonality assumptions; they are not a general rule for every ridge fit.

The following examples use sufficient summaries of centered, orthogonal standardized design matrices. The vector \(b\) supplies the ordinary least-squares coefficients, so the calculations do not require listing every row of the data. Each example uses the same objective above.

Worked Example: A Small Penalty

A hypothetical pricing analysis has two centered, orthogonal standardized predictors. The ordinary least-squares coefficient vector is \(b=(4,-2)\). Using \(\lambda=0.1\), calculate the ridge coefficients and the fitted contribution for a case with predictor values \((0.5,-1)\). State the method and identify a common mistake to avoid.

Method. Because the predictors are orthogonal and standardized, divide each ordinary least-squares coefficient by \(1+\lambda\):

$$ 1+\lambda=1+0.1=1.1, \qquad \widehat{\boldsymbol{\beta}}_{0.1} = \left(\frac{4}{1.1},\frac{-2}{1.1}\right) = \left(\frac{40}{11},-\frac{20}{11}\right). $$

The coefficients are approximately \((3.6364,-1.8182)\), rounded to four decimal places. The fitted contribution at \((0.5,-1)\), excluding the intercept, is

$$ 0.5\left(\frac{40}{11}\right) +(-1)\left(\frac{-20}{11}\right) = \frac{20}{11}+\frac{20}{11} = \frac{40}{11} \approx 3.6364. $$

As a check, the unpenalized contribution at this case would be \(0.5(4)+(-1)(-2)=4\). The ridge contribution is smaller. The common mistake is to subtract \(0.1\) from each coefficient, producing \((3.9,-2.1)\). That is not the ridge formula: the stated objective gives a multiplicative factor of \(1/1.1\) in this orthogonal case.

Worked Example: A Moderate Penalty

A hypothetical retention model has two centered, orthogonal standardized predictors, with ordinary least-squares coefficients \((3,1.5)\). For \(\lambda=1\), calculate the ridge coefficients and the fitted contribution for a case with predictor values \((2,-1)\). Explain how the penalty changes the prediction.

Method. Apply the orthogonal-design formula, using \(1+\lambda=2\):

$$ \widehat{\boldsymbol{\beta}}_1 = \left(\frac{3}{2},\frac{1.5}{2}\right) = (1.5,0.75). $$

The fitted contribution is

$$ 2(1.5)+(-1)(0.75)=3-0.75=2.25. $$

Without the penalty, the contribution would be \(2(3)+(-1)(1.5)=6-1.5=4.5\). It is exactly half as large here because the orthogonal-design shrinkage factor is \(1/(1+1)=1/2\). This comparison concerns the predictor contribution, not necessarily the full prediction: an unpenalized intercept, if present, must still be added.

A common mistake is to say that every fitted prediction must be half its ordinary least-squares value. The coefficients are halved in this example, but a prediction that includes a nonzero intercept is not generally halved. The intercept is not penalized under the stated setup.

Worked Example: A Large Penalty Relative to the Stated Objective

A hypothetical equipment-maintenance model has two centered, orthogonal standardized predictors with ordinary least-squares coefficients \((5,-2.5)\). For \(\lambda=9\), calculate the ridge coefficients and the fitted contribution for predictor values \((-1,2)\). Check the result against the unpenalized contribution.

Method. The denominator is \(1+\lambda=10\), so

$$ \widehat{\boldsymbol{\beta}}_9 = \left(\frac{5}{10},\frac{-2.5}{10}\right) = (0.5,-0.25). $$

At \((-1,2)\), the ridge contribution is

$$ (-1)(0.5)+2(-0.25)=-0.5-0.5=-1. $$

The unpenalized contribution is \((-1)(5)+2(-2.5)=-5-5=-10\). The ridge contribution is one tenth as large, as expected from \(1/(1+9)=0.1\). This is a large penalty relative to the loss scale and predictor scaling in this example; the label “large” is not an absolute classification of \(\lambda=9\) for every data set.

The common mistake is to interpret \(\lambda=9\) as a 9% reduction. The shrinkage factor here is \(1/10\), not \(1-0.09\). The factor follows from the objective and the orthogonal-design conditions.

Why Ridge Shrinks: A Short Derivation

The orthogonal case makes the arithmetic simple. A matrix derivation shows how \(\lambda\) acts more generally and clarifies which statements about shrinkage remain valid. Let \(A=X^\mathsf{T}X/n\) and \(b=X^\mathsf{T}y/n\). Differentiating the stated objective with respect to \(\boldsymbol{\beta}\), setting the gradient to zero, and rearranging gives the ridge normal equations:

$$ \nabla Q_\lambda(\boldsymbol{\beta}) = -A\left(\frac{X^\mathsf{T}y}{X^\mathsf{T}y}\right) +\lambda\boldsymbol{\beta} $$

The displayed gradient expression above would not correctly represent the derivative: the response cross-product must remain a vector, not a scalar ratio. In full, the correct calculation is

$$ \nabla Q_\lambda(\boldsymbol{\beta}) = -\frac{X^\mathsf{T}y}{n} +\frac{X^\mathsf{T}X}{n}\boldsymbol{\beta} +\lambda\boldsymbol{\beta} = -b+(A+\lambda I)\boldsymbol{\beta}. $$

Setting this equal to zero yields

$$ (A+\lambda I)\widehat{\boldsymbol{\beta}}_\lambda=b, \qquad \widehat{\boldsymbol{\beta}}_\lambda=(A+\lambda I)^{-1}b \quad\text{when }\lambda>0. $$

For \(\lambda>0\), \(A+\lambda I\) is invertible because \(A\) is positive semidefinite. If \(A\) has eigenvalues \(d_j\geq 0\) and orthonormal eigenvectors collected in \(V\), then \(A=V\operatorname{diag}(d_j)V^\mathsf{T}\). In these eigen-directions, the ridge solution has components

$$ \left(V^\mathsf{T}\widehat{\boldsymbol{\beta}}_\lambda\right)_j = \frac{\left(V^\mathsf{T}b\right)_j}{d_j+\lambda}. $$

This denominator explains why the same numerical increase in \(\lambda\) need not have the same effect in every direction: the data contribute different \(d_j\) values. When ordinary least squares is uniquely defined, \(b=A\widehat{\boldsymbol{\beta}}_{\mathrm{OLS}}\), so each corresponding eigen-direction is multiplied relative to its least-squares value by \(d_j/(d_j+\lambda)\). In the standardized orthogonal case, all \(d_j=1\), recovering \(1/(1+\lambda)\).

This argument establishes shrinkage most directly in the eigen-directions, not necessarily in each original predictor coordinate. With correlated predictors, changing \(\lambda\) can cause an individual coefficient to increase in absolute value or change sign even while the overall coefficient vector is being regularized. It is therefore safer to say that ridge controls the overall coefficient fit, and that directional components are attenuated, than to claim that every displayed coefficient must move monotonically toward zero.

How to Interpret a Lambda Value

A numerical \(\lambda\) has meaning only in relation to the complete fitting setup. The objective states how the residual term is scaled and how the penalty is applied. Predictor scaling matters as well: changing a predictor’s units changes the coefficient size needed to describe the same relationship, and therefore changes its relationship to a squared-coefficient penalty. Standardizing predictors before fitting makes the penalty more comparable across predictors, but it does not make a \(\lambda\) value universal across data sets or objective conventions.

When interpreting a result, keep these distinctions clear:

  • Penalty strength: within the same setup, increasing \(\lambda\) gives the penalty more influence relative to the residual loss.
  • Coefficient shrinkage: the fitted coefficients respond continuously to \(\lambda\); ridge does not generally set coefficients exactly to zero.
  • Prediction change: a changed coefficient vector changes predictor contributions, but the total prediction also depends on the case’s predictor values and any intercept.
  • Comparability: a \(\lambda\) from one objective or scaling cannot be interpreted by simply carrying over the numerical label to a different setup.

In practice, analysts compare candidate penalty values using an appropriate model assessment procedure. The value selected is not interpreted as a percentage of coefficient reduction. It is the penalty setting that performed best according to the chosen assessment, given the fitting convention and data preparation. The fitted coefficients and predictions then describe the actual effect in context.

Common Exam Trap: Treating Lambda as a Direct Shrinkage Percentage

Suppose the standardized orthogonal model in the first example has coefficient \(4\) and \(\lambda=0.1\). A tempting but incorrect calculation is \(4(1-0.1)=3.6\), treating \(\lambda\) as a 10% reduction. The correct calculation under the stated objective is

$$ \widehat{\beta}_{0.1}=\frac{4}{1+0.1} =\frac{40}{11} \approx 3.6364, $$

rounded to four decimal places. The incorrect value \(3.6\) is close in this particular case, but it does not follow from the ridge objective. For a larger penalty, the difference can be substantial: at \(\lambda=9\), the correct factor in this same special design is \(1/10\), whereas \(1-\lambda\) is negative. A negative “shrinkage factor” is plainly not a general ridge rule.

Key takeaway: Interpret \(\lambda\) through the objective, predictor scaling, and design matrix. For orthogonal standardized predictors under the stated objective, coefficients are divided by \(1+\lambda\). In general designs, \(\lambda\) controls shrinkage in the predictor cross-product matrix’s eigen-directions, and individual original-scale coefficients need not shrink monotonically.

Check Your Understanding

Use the stated objective and show enough intermediate work to identify the relevant shrinkage factor. Assume centered, orthogonal standardized predictors wherever a question gives ordinary least-squares coefficients.

  1. A two-predictor model has ordinary least-squares coefficients \((2,-6)\) and uses \(\lambda=1\). Find the ridge coefficients. (Answer: \((1,-3)\))
  2. A model has coefficients \((4,2)\) before shrinkage and uses \(\lambda=0.25\). Find the ridge coefficients and the predictor contribution at \((1,-2)\). (Answer: coefficients \((3.2,1.6)\); contribution \(0\))
  3. A model has ordinary least-squares coefficients \((6,-3)\) and uses \(\lambda=3\). Find the ridge coefficients and the contribution at \((2,1)\). (Answer: coefficients \((1.5,-0.75)\); contribution \(2.25\))
  4. In a principal direction with eigenvalue \(d=4\), find the relative shrinkage factor at \(\lambda=1\). Repeat for a direction with \(d=1\). (Answer: \(4/5=0.8\) and \(1/2=0.5\), respectively)
  5. For orthogonal standardized predictors, a coefficient of \(2\) is to be reduced to \(1\) under the stated objective. Find the required \(\lambda\). (Answer: \(\lambda=1\))
Clinical Biostats