Tutorials › High-Dimensional Genomic Data Analysis › Ridge Regression From Singular Value Decomposition

Penalized Regression for p Much Larger Than n · Tutorial 515 of 795

Ridge Regression From Singular Value Decomposition

Learn to express the ridge estimator using the singular value decomposition and verify when its solution is unique, even if ordinary least squares coefficients are not.

Advanced 10 min read

What You'll Learn

  • State the ridge objective and the conditions needed for a unique coefficient estimate.
  • Derive the SVD form of the ridge estimator from the penalized normal equations.
  • Work through ridge fits for rank-deficient designs, including a case with an exactly computed coefficient of 0.8.
  • Distinguish a unique ridge estimate from a unique ordinary least squares estimate.
  • Identify implementation and interpretation pitfalls, including mishandling the intercept or penalty parameter.

Why Derive Ridge With the SVD?

When the number of predictors exceeds the number of observations, or when predictors are linearly dependent, the design matrix does not have full column rank. In that situation, ordinary least squares cannot uniquely determine every coefficient: multiple coefficient vectors can give the same fitted values. Ridge regression adds a positive penalty to the least-squares objective. The singular value decomposition (SVD) makes explicit how this changes the coefficient calculation and why the resulting estimate is unique.

The derivation below concerns the coefficient vector for a fixed positive penalty parameter. It does not choose that parameter. As in the earlier material on Predictor Scaling Before Penalization, the predictor scale matters: the penalty acts on the coefficients as represented in the design matrix. For clarity, treat any intercept separately and do not penalize it; equivalently, the response and predictors can first be adjusted for the intercept. The matrix \(X\) below is the design matrix for the coefficients being penalized.

Definition: For a response vector \(y\in\mathbb{R}^n\), design matrix \(X\in\mathbb{R}^{n\times p}\), and penalty parameter \(\lambda>0\), ridge regression estimates \(\beta\in\mathbb{R}^p\) by minimizing
$$ Q(\beta)=\frac{1}{2}\|y-X\beta\|_2^2+\frac{\lambda}{2}\|\beta\|_2^2. $$
Here \(\|v\|_2^2=v^\mathsf{T}v\). The first term measures residual sum of squares, and the second penalizes the squared Euclidean length of the coefficient vector. The factor \(1/2\) is a convenient scaling and does not change the minimizer relative to the objective \(\|y-X\beta\|_2^2+\lambda\|\beta\|_2^2\).

The assumptions needed for the algebra are modest: \(X\) and \(y\) are finite real-valued matrices/vectors of compatible dimensions, and \(\lambda\) is strictly positive. No full-rank assumption on \(X\) is required. A statistical model such as \(y=X\beta+\varepsilon\) can be used to motivate the fit, but the existence and uniqueness result below follows directly from the objective and does not require normally distributed errors.

From the Penalized Normal Equations to the SVD

Differentiate \(Q(\beta)\) with respect to \(\beta\). Setting its gradient to zero gives the penalized normal equations:

$$ \nabla Q(\beta)=X^\mathsf{T}X\beta-X^\mathsf{T}y+\lambda\beta=0, \qquad (X^\mathsf{T}X+\lambda I_p)\beta=X^\mathsf{T}y. $$

For ordinary least squares, \(X^\mathsf{T}X\) is singular when \(X\) is rank deficient, so it cannot be inverted to obtain a unique coefficient vector. Ridge adds \(\lambda I_p\). For any nonzero \(z\in\mathbb{R}^p\),

$$ z^\mathsf{T}(X^\mathsf{T}X+\lambda I_p)z =\|Xz\|_2^2+\lambda\|z\|_2^2>0. $$

The inequality holds because \(\|Xz\|_2^2\geq 0\), \(\|z\|_2^2>0\), and \(\lambda>0\). Thus \(X^\mathsf{T}X+\lambda I_p\) is positive definite and invertible. The objective is strictly convex, so its minimizer is unique, regardless of the rank of \(X\).

To write that minimizer in SVD form, let \(r=\operatorname{rank}(X)\) and use the compact SVD \(X=U_rD_rV_r^\mathsf{T}\). The columns of \(U_r\in\mathbb{R}^{n\times r}\) and \(V_r\in\mathbb{R}^{p\times r}\) are orthonormal, and \(D_r=\operatorname{diag}(d_1,\ldots,d_r)\), where every singular value \(d_j\) is positive. Substitution into the penalized normal equations gives the expression below.

$$ \begin{aligned} X^\mathsf{T}X+\lambda I_p &=V_rD_r^2V_r^\mathsf{T}+\lambda I_p,\\ X^\mathsf{T}y&=V_rD_rU_r^\mathsf{T}y,\\ \hat{\beta}_{\mathrm{ridge}} &=V_r\operatorname{diag}\left( \frac{d_1}{d_1^2+\lambda},\ldots, \frac{d_r}{d_r^2+\lambda} \right)U_r^\mathsf{T}y. \end{aligned} $$

One way to verify the last line is to substitute it into the normal equations. Multiplication by \(X^\mathsf{T}X+\lambda I_p\) applies \(d_j^2+\lambda\) to the coefficient along each column of \(V_r\), canceling its denominator and leaving \(V_rD_rU_r^\mathsf{T}y=X^\mathsf{T}y\). Components in the null space of \(X\), which are orthogonal to the columns of \(V_r\), are zero in this solution. The positive penalty makes any nonzero such component increase the objective without changing the fitted values.

Key result: If \(X=U_rD_rV_r^\mathsf{T}\) is the compact SVD and \(\lambda>0\), the unique ridge estimate is \(\hat{\beta}_{\mathrm{ridge}}=V_r\operatorname{diag}(d_j/(d_j^2+\lambda))U_r^\mathsf{T}y\). This formula remains valid when \(r<p\), including when \(p>n\).

Worked SVD Calculations

Worked Example: A Rank-Deficient Design With a Coefficient of 0.8

Consider the hypothetical design and response \(X=\begin{bmatrix}2&0&0\\0&1&0\end{bmatrix}\) and \(y=(2,1)^\mathsf{T}\), with \(\lambda=1\). The third column is zero, so \(X\) has rank 2 although it has 3 columns. Its compact SVD has \(U_r=I_2\), \(D_r=\operatorname{diag}(2,1)\), and \(V_r\) consisting of the first two coordinate vectors in \(\mathbb{R}^3\).

The SVD formula gives the first coefficient as \(2/(2^2+1)\times 2=4/5=0.8\), and the second as \(1/(1^2+1)\times 1=1/2=0.5\). The third coefficient is zero because its direction is in the null space of \(X\). Thus \(\hat{\beta}_{\mathrm{ridge}}=(0.8,0.5,0)^\mathsf{T}\).

The fitted response is \(X\hat{\beta}_{\mathrm{ridge}}=(1.6,0.5)^\mathsf{T}\), so the residual is \((0.4,0.5)^\mathsf{T}\). The residual sum of squares is \(0.4^2+0.5^2=0.41\), and the penalty contribution before multiplying by \(\lambda/2\) is \(0.8^2+0.5^2+0^2=0.89\). Therefore \(Q(\hat{\beta}_{\mathrm{ridge}})=0.41/2+0.89/2=0.65\). The estimate is unique even though the unpenalized least-squares coefficient for the zero column could be arbitrary.

Worked Example: Two Identical Predictors

Suppose the hypothetical design has two identical columns, \(X=\begin{bmatrix}1&1\\2&2\end{bmatrix}\), with \(y=(1,0)^\mathsf{T}\) and \(\lambda=2\). This matrix has rank 1. Its nonzero singular value is \(\sqrt{10}\), with left singular vector \(u=(1,2)^\mathsf{T}/\sqrt{5}\) and right singular vector \(v=(1,1)^\mathsf{T}/\sqrt{2}\).

First, \(u^\mathsf{T}y=1/\sqrt{5}\). The SVD coefficient vector is therefore \(v\{\sqrt{10}/(10+2)\}(1/\sqrt{5})\). Since \(\sqrt{10}/\sqrt{5}=\sqrt{2}\), this equals \((1,1)^\mathsf{T}/12\). Each estimated coefficient is \(1/12\).

The fitted values are \((1/6,1/3)^\mathsf{T}\), and the residuals are \((5/6,-1/3)^\mathsf{T}\). Hence the residual sum of squares is \(25/36+1/9=29/36\), while \(\|\hat{\beta}_{\mathrm{ridge}}\|_2^2=2/144=1/72\). The objective value is \((29/36)/2+(2/2)(1/72)=29/72+1/72=5/12\). Without the penalty, the data identify the sum of the two coefficients but not their separate values. Ridge gives a unique pair because the penalty distinguishes coefficient vectors with different squared lengths.

Worked Example: A Response Component Outside the Column Space

Take the hypothetical matrix \(X=\operatorname{diag}(2,1,0)\), response \(y=(2,1,3)^\mathsf{T}\), and \(\lambda=1\). The rank is 2. The nonzero singular values are 2 and 1, with left and right singular vectors equal to the first two coordinate vectors. The third response component is orthogonal to the column space of \(X\).

The coefficient calculation is \(2(2)/(4+1)=0.8\) for the first coordinate and \(1(1)/(1+1)=0.5\) for the second. The third coefficient is zero, so \(\hat{\beta}_{\mathrm{ridge}}=(0.8,0.5,0)^\mathsf{T}\) and the fitted values are \((1.6,0.5,0)^\mathsf{T}\). The residual is \((0.4,0.5,3)^\mathsf{T}\); the component 3 cannot be fitted by any coefficient vector because the third row of \(X\) is zero.

The residual sum of squares is \(0.16+0.25+9=9.41\), and the squared coefficient length is \(0.64+0.25=0.89\). Thus \(Q=9.41/2+0.89/2=5.15\). The example separates two facts: ridge resolves coefficient nonuniqueness, but it cannot fit a response component outside the column space of the design.

Assumptions, Diagnostics, and Alternatives

The unique-solution result requires only \(\lambda>0\) and a finite design matrix. It does not assert that ridge coefficients are unbiased estimates of an underlying parameter, nor that the chosen penalty is suitable for prediction. Those are separate questions. The formula also depends on the stated objective: using a different scaling of the residual term changes the numerical meaning of \(\lambda\), unless the penalty is rescaled accordingly.

A practical calculation should check that the fit used the intended \(\lambda\), applied the penalty to the intended coefficients, and treated the intercept consistently. In numerical software, singular values very close to zero can be sensitive to floating-point precision; a reported numerical rank depends on the tolerance used. This does not invalidate the mathematical formula, but it can affect computed SVD components. Confirm that the singular values and design dimensions are plausible, and compare the SVD solution with a direct solve of \((X^\mathsf{T}X+\lambda I_p)\hat{\beta}=X^\mathsf{T}y\) on a small problem.

The ordinary least-squares solution is the main contrast. When \(X\) has full column rank, it is uniquely given by \((X^\mathsf{T}X)^{-1}X^\mathsf{T}y\); when \(X\) is rank deficient, least-squares fitted values remain defined but the coefficient vector is not unique. The Moore–Penrose pseudoinverse selects the least-squares coefficient vector of smallest Euclidean length. Ridge instead solves a penalized objective for a positive \(\lambda\), giving a unique coefficient vector. A truncated SVD is another possible approach: it discards selected small-singular-value components, whereas ridge retains the nonzero SVD components with modified factors. These approaches answer related but not identical estimation questions.

A frequent error is to say, “\(X^\mathsf{T}X\) is singular, so ridge cannot be computed.” That reasoning overlooks the penalty term. The matrix that must be inverted is \(X^\mathsf{T}X+\lambda I_p\), not \(X^\mathsf{T}X\) alone, and for every \(\lambda>0\) it is positive definite. A different error is to set \(\lambda=0\) while still claiming ridge has produced a unique solution. At \(\lambda=0\), the objective is ordinary least squares and rank deficiency again allows multiple coefficient vectors. As \(\lambda\) decreases toward zero, the ridge solution approaches the minimum-length least-squares solution, but that limiting statement does not make the \(\lambda=0\) coefficient unique in general.

Common pitfall: Adding a penalty does not mean every component of the response can be fitted, and it does not repair a misspecified design. It makes the penalized coefficient optimization strictly convex and its minimizer unique for \(\lambda>0\); fitted values still lie in the column space of \(X\).

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. For \(X\in\mathbb{R}^{n\times p}\), what condition on \(\lambda\) ensures that \(X^\mathsf{T}X+\lambda I_p\) is positive definite, even if \(X\) is rank deficient?
  2. If the nonzero singular value is \(d=3\), the corresponding component of \(U_r^\mathsf{T}y\) is 2, and \(\lambda=3\), what is the corresponding SVD coefficient multiplier and coefficient component?
  3. Why does a zero column of \(X\) have a zero ridge coefficient when \(\lambda>0\)?
  4. Does a unique ridge coefficient vector imply that every response value can be fitted exactly? Explain.

Solutions. (1) Require \(\lambda>0\): for any nonzero \(z\), \(z^\mathsf{T}(X^\mathsf{T}X+\lambda I_p)z=\|Xz\|_2^2+\lambda\|z\|_2^2>0\). (2) The multiplier is \(d/(d^2+\lambda)=3/(9+3)=1/4\); multiplying by the response component 2 gives coefficient component \(1/2\). (3) A zero column contributes nothing to \(X\beta\), but a nonzero coefficient for it increases \(\lambda\|\beta\|_2^2/2\), so the unique minimizer sets it to zero. (4) No. Fitted values must belong to the column space of \(X\); a response component outside that space remains in the residual even though the penalized coefficient minimizer is unique.

Clinical Biostats