Why Ridge Has Effective, Rather Than Ordinary, Degrees of Freedom
In ordinary least squares, the fitted values are a projection of the observed response onto the space spanned by the model columns. The trace of that projection matrix equals the dimension of the space, so it counts the fitted model’s degrees of freedom. Ridge regression changes the fitted values by shrinking contributions from predictor directions. Its smoother matrix is generally not a projection, and its trace need not be an integer. That trace provides a useful measure of how much flexibility the ridge fit uses.
The key is to define the model and penalty precisely. Here, the predictors are centered, the intercept is not penalized, and the ridge penalty is \(\lambda\) times the sum of squared slope coefficients. For \(\lambda>0\), the ridge fit is a linear function of the response. Its smoother matrix makes it possible to quantify the fit’s complexity, while a singular-value decomposition reveals which predictor directions contribute most.
The Ridge Model and Its Smoother Matrix
Let \(y\) be the \(n\)-vector of observed responses and let \(X\) be the \(n\times p\) design matrix of centered predictor columns. With an intercept, write the ridge objective as
Here \(\beta_0\) is the intercept, \(\boldsymbol{\beta}\) is the \(p\)-vector of slopes, and \(\lambda\) is the penalty parameter for this stated objective. Since the columns of \(X\) are centered, the intercept estimate is \(\bar{y}\); equivalently, the slope fit can be obtained by fitting the centered response \(y_c=y-\bar{y}\mathbf{1}\). This separates the intercept from the predictor contribution.
For \(\lambda>0\), the matrix \(X^\mathsf{T}X+\lambda I_p\) is invertible, even if \(X\) is rank deficient. The centered ridge fitted values are \(X(X^\mathsf{T}X+\lambda I_p)^{-1}X^\mathsf{T}y_c\). Adding back the intercept gives the full fitted-value smoother matrix:
The first term maps \(y\) to its mean in every observation, and the second maps the centered response to the ridge predictor fit. Because \(X\) is centered, its columns are orthogonal to \(\mathbf{1}\), so these contributions are separated. The intercept term has trace one. At \(\lambda=0\), do not use the displayed inverse formula unless \(X^\mathsf{T}X\) is known to be invertible. For any rank, the zero-penalty predictor fit is instead the least-squares projection onto \(\operatorname{col}(X)\).
Deriving the Singular-Value Formula
Let \(r=\operatorname{rank}(X)\), and write a reduced singular-value decomposition using only the positive singular values:
The columns of \(U_r\) are orthonormal vectors in observation space, and those of \(V_r\) are orthonormal vectors in predictor space. Substituting this decomposition into the predictor part of the smoother and using \(V_r^\mathsf{T}V_r=I_r\) gives
Taking the trace uses the fact that for compatible matrices, \(\operatorname{tr}(AB)=\operatorname{tr}(BA)\). The trace of the intercept term is one, and each diagonal entry in the singular-direction representation contributes its shrinkage weight. Therefore:
The zero-penalty result also follows by taking the limit in the singular-value formula: each positive singular value contributes \(d_j^2/(d_j^2+0)=1\). Singular directions with zero singular value are not included in the sum, since they do not belong to the column space of \(X\). Thus the zero-penalty statement remains valid when \(X\) is rank deficient.
Worked Calculations
Worked Example: Two Singular Directions at Two Penalties
Hypothetical setup. Suppose centered predictors have positive singular values \(d_1=3\) and \(d_2=1\), and there is an unpenalized intercept. The design has rank \(r=2\). Calculate effective degrees of freedom at \(\lambda=1\) and \(\lambda=4\).
For \(\lambda=1\), the singular-value formula gives
At \(\lambda=4\), the calculation is
The penalty increase reduces the predictor contribution from \(1.400\) to about \(0.8923\), while the intercept continues to contribute one. The result is not a count of retained predictors: it is the trace-based effective flexibility of the ridge fit.
Worked Example: A Rank-Deficient Design at Zero and Positive Penalty
Hypothetical setup. Let \(n=4\), let \(z=(-1,0,1,0)^\mathsf{T}\), and suppose the two centered predictor columns are identical: \(X=[z,z]\). Since \(z^\mathsf{T}z=2\), the matrix \(X^\mathsf{T}X\) is
This matrix has rank one, with its single positive eigenvalue equal to \(4\). Therefore \(X\) has rank \(r=1\) and one positive singular value with \(d_1^2=4\). At \(\lambda=2\),
At \(\lambda=0\), \(X^\mathsf{T}X\) is singular, so an ordinary inverse cannot be used. Instead the predictor smoother is the projection onto the one-dimensional space spanned by \(z\); its trace is one. Including the intercept gives \(df_{\mathrm{eff}}(0)=1+1=2\). The duplicate columns do not create a second independent predictor direction.
Worked Example: Strong and Weak Singular Directions
Hypothetical setup. Consider a centered design with three positive squared singular values \(16\), \(4\), and \(1\), plus an unpenalized intercept. Compare \(\lambda=3\) with \(\lambda=12\).
At \(\lambda=3\), the directions contribute \(16/19\), \(4/7\), and \(1/4\), respectively:
At \(\lambda=12\), their contributions are \(16/28\), \(4/16\), and \(1/13\):
The direction with squared singular value \(1\) contributes only \(0.07692\) at \(\lambda=12\), while the direction with squared singular value \(16\) contributes \(0.5714\). For the same penalty, directions with larger squared singular values retain a larger share of their unpenalized contribution.
How the Penalty Changes Effective Degrees of Freedom
Each predictor direction contributes the fraction \(d_j^2/(d_j^2+\lambda)\). For \(\lambda\geq 0\), this contribution is one at zero penalty, lies strictly between zero and one for positive penalty, and approaches zero as the penalty grows without bound. The intercept remains unpenalized under the model defined here. For \(\lambda>0\), differentiating the sum makes the direction of change explicit:
Thus increasing \(\lambda\) strictly decreases effective degrees of freedom when the predictor design has positive rank. At zero penalty, the value is \(1+r\); as \(\lambda\) tends to infinity, it approaches one, the intercept contribution. If there are no predictor directions, \(r=0\), it is one for every penalty. Without an intercept, the corresponding predictor-only formula omits the leading one.
Effective degrees of freedom can be fractional because ridge shrinks directions rather than simply retaining or discarding them. The trace summarizes the total influence of the response on its fitted values. It is useful for describing model flexibility, but it is not the number of nonzero slope coefficients and should not be interpreted as such. For a fixed design and penalty, it depends on the design’s singular values; changing predictor scaling or the penalty convention changes the numerical setup and must be accounted for when comparing values.
Common Mistake
A common error is to substitute \(\lambda=0\) into \((X^\mathsf{T}X+\lambda I_p)^{-1}\) even when the design is rank deficient. In that case \(X^\mathsf{T}X\) is singular and the inverse does not exist. The correction is to use the projection onto \(\operatorname{col}(X)\), equivalently \(XX^+\), at zero penalty; its trace is \(r\). Another related error is to count every predictor column as a separate direction. When columns are dependent, only the rank \(r\) counts at zero penalty, and only the positive singular values appear in the ridge formula.
Check Your Understanding
Use the stated convention of centered predictors and an unpenalized intercept.
- A design has rank three. What is its effective degrees of freedom at \(\lambda=0\), including the intercept?
- For a positive singular value \(d\), explain why its ridge contribution is between zero and one when \(\lambda>0\).
- A design has positive squared singular values \(9\) and \(1\). Calculate effective degrees of freedom at \(\lambda=2\).
- What matrix should define the predictor smoother at \(\lambda=0\) when \(X\) is rank deficient, and what is the trace of that smoother?
- As \(\lambda\) tends to infinity, what value does effective degrees of freedom approach in this intercept model, and why?