All notes / Mathematics of machine learning

Ridge Regression and the Influence of a Single Point

Lagrange multipliers, Cook’s distance, and Sherman–Morrison

Will Gao · March 2025

Contents
  1. 1 Linear Regression
  2. 1.1 Probabilistic Formulation
  3. 2 Regularization and Influence Diagnostics
  4. 3 Ridge Regression
  5. 3.1 Constrained Formulation
  6. 3.2 A Geometric View of Lagrange Multipliers
  7. 3.3 Unconstrained Formulation
  8. 3.4 Relation Between the Constrained and Penalized Forms
  9. 4 Cook’s Distance
  10. 4.1 Matrix Determinant Lemma
  11. 4.2 Sherman–Morrison Formula
  12. 4.3 Derivation of the Influence Formula
  13. 5 Autoregression

These notes are adapted from Prof. Alexis Drouot’s MATH 480 course at the University of Washington, Seattle (Winter 2025). They focus on several topics around linear regression: its probabilistic formulation, Ridge regularization, influence diagnostics through Cook’s distance, and the representation of autoregressive models as linear regressions. I have done my best to ensure correctness, but errors may remain.

1Linear Regression

1.1Probabilistic Formulation

Consider a dataset of N observations

{(xi,yi)}i=1N,

where xiRd are the predictors and yiR is the response.

In the probabilistic formulation of linear regression, we assume

yi=xia+ϵi,

where aRd is the parameter vector and

ϵii.i.d.N(0,σ2).

Hence

p(yixi,a,σ2)=12πσ2exp((yixia)22σ2).

Assuming the observations are independent,

p(yX,a,σ2)=i=1N12πσ2exp((yixia)22σ2).

Taking logarithms,

logp(yX,a,σ2)=N2log(2πσ2)12σ2i=1N(yixia)2.

Therefore, for fixed σ2, maximizing the likelihood with respect to a is equivalent to minimizing

i=1N(yixia)2.

In matrix notation,

L(a)=Xay2,

where XRN×d is the design matrix and yRN is the response vector.

The gradient and Hessian are

L(a)=2X(Xay),2L(a)=2XX.

If X has linearly independent columns, then XX is positive definite, so L is strictly convex and the OLS minimizer is unique:

aOLS=(XX)1Xy.

If the Gaussian i.i.d. noise assumption is changed, the corresponding likelihood—and hence the natural loss function—may also change.

2Regularization and Influence Diagnostics

OLS can be sensitive to influential observations because squared residuals place substantial weight on large errors. Ridge regression does not make least squares robust in the usual statistical sense; instead, it stabilizes coefficient estimates by shrinking their magnitude and is especially useful in settings involving multicollinearity, ill-conditioning, or high variance.

Influential observations can be studied separately using diagnostics such as Cook’s distance. Such diagnostics are best interpreted as tools for identifying observations that deserve further investigation, rather than as automatic rules for deleting data.

We first study Ridge regression and then return to influence diagnostics.

3Ridge Regression

3.1Constrained Formulation

A constrained form of Ridge regression is

(Mt)minaXay2subject toa2t,

where t0.

The feasible set

Bt={aRd:a2t}

is compact, and the objective is continuous, so a minimizer exists.

If aOLS satisfies

aOLS2t,

then the constraint is inactive and the constrained solution is simply aOLS.

Otherwise, the optimum must lie on the boundary:

a2=t.

Because the problem is convex, the Karush–Kuhn–Tucker conditions characterize the optimum. Introduce

L(a,λ)=Xay2+λ(a2t),

with λ0.

The KKT conditions are

aL(a,λ)=0,a2t,λ0,

and

λ(a2t)=0.

The stationarity condition gives

2X(Xay)+2λa=0,

so

(XX+λId)a=Xy.

If λ>0, then XX+λId is positive definite because, for any nonzero v,

v(XX+λId)v=Xv2+λv2>0.

Hence it is invertible, even if X does not have linearly independent columns.

Therefore,

a=(XX+λId)1Xy.

The complementary-slackness condition separates the two cases:

  1. If λ=0, the constraint is inactive and a=aOLS, assuming the OLS solution is uniquely defined.
  2. If λ>0, then the constraint is active: a2=t.

3.2A Geometric View of Lagrange Multipliers

For completeness, consider the equality-constrained problem

minaf(a)subject tog(a)=0.

Let

S={aRd:g(a)=0},

and suppose aS is a local extremum with g(a)0.

The tangent space at a can be described by

TaS={γ(0):γ:(ε,ε)S,γ(0)=a},

where γ is C1.

For any such curve,

ddtf(γ(t))|t=0=f(a)γ(0).

Since a is a local extremum of f restricted to S,

f(a)v=0vTaS.

By the regular-level-set theorem,

TaS=(span{g(a)}).

Thus

f(a)span{g(a)},

so there exists λR such that

f(a)+λg(a)=0.

This is the usual Lagrange-multiplier condition. It is a necessary condition for regular constrained local extrema, not in general a sufficient condition for global optimality.

3.3Unconstrained Formulation

The more common form of Ridge regression is

(Mλ)minaXay2+λa2,

where λ>0.

Define

Lλ(a)=Xay2+λa2.

Then

Lλ(a)=2X(Xay)+2λa,2Lλ(a)=2XX+2λId.

For any nonzero h,

h2Lλ(a)h=2Xh2+2λh2>0.

Thus Lλ is strictly convex for every λ>0, regardless of whether X has full column rank. Consequently, it has a unique minimizer satisfying

(XX+λId)a=Xy,

namely

a=(XX+λId)1Xy.

3.4Relation Between the Constrained and Penalized Forms

The constrained and penalized formulations describe the same family of nonzero Ridge solutions, with some care at the endpoints.

Suppose t>0, and let at solve

minaXay2subject toa2t.

By the KKT conditions, there exists λt0 such that

(XX+λtId)at=Xy.

Therefore, at also minimizes

Xay2+λta2.

Conversely, for any λ>0, let

aλ=(XX+λId)1Xy

and set t=aλ2. Then aλ solves the constrained problem with radius t.

There are two endpoint subtleties:

  • If the constraint is sufficiently loose, then λ=0 and the constrained solution is OLS.
  • If t=0, the constrained solution is a=0. In general this is not obtained for any finite λ, but aλ0 as λ.

4Cook’s Distance

Cook’s distance is an influence diagnostic that measures how much the fitted regression model changes when a single observation is removed.

Assume X has full column rank. Let

a=(XX)1Xy

be the OLS estimator using all observations.

For observation j, let Xj and yj denote the dataset with the j-th observation removed, and define the leave-one-out estimator

a(j)=(XjXj)1Xjyj,

assuming Xj also has full column rank.

To compare the two fitted models on the same N design points, define the unscaled influence measure

Dj=XaXa(j)2.

Let

H=X(XX)1X

be the hat matrix. We will show that

Dj=Hjj(1Hjj)2(yjxja)2.

4.1Matrix Determinant Lemma

Lemma 1. Suppose A is an invertible n×n matrix and u,vRn. Then

det(A+uv)=(1+vA1u)det(A).

Proof. First consider A=I. We have

(I0v1)(I+uvu01)(I0v1)=(Iu01+vu).

The first and third matrices have determinant 1, so

det(I+uv)=1+vu.

For general A,

A+uv=A(I+A1uv),

and therefore

det(A+uv)=det(A)det(I+(A1u)v)=det(A)(1+vA1u).

4.2Sherman–Morrison Formula

Lemma 2. Let A be invertible and suppose 1+vA1u0. Then

(A+uv)1=A1A1uvA11+vA1u.

Proof. By the matrix determinant lemma, A+uv is invertible. Define

B=A1A1uvA11+vA1u.

A direct multiplication shows

(A+uv)B=I.

Hence B=(A+uv)1.

4.3Derivation of the Influence Formula

Since removing the j-th observation gives

XjXj=XXxjxj,

the Sherman–Morrison formula yields

(XjXj)1=(XX)1+(XX)1xjxj(XX)11xj(XX)1xj,

provided

1xj(XX)1xj0.

Also,

Xjyj=Xyxjyj.

Let

hjj=xj(XX)1xj=Hjj.

A calculation gives

aa(j)=(XX)1xj1hjj(yjxja).

Therefore

XaXa(j)=X(XX)1xj1hjj(yjxja),

so

Dj=XaXa(j)2=X(XX)1xj2(1hjj)2(yjxja)2=xj(XX)1XX(XX)1xj(1hjj)2(yjxja)2=hjj(1hjj)2(yjxja)2.

This is an unscaled version of Cook’s distance. A common conventional definition additionally divides by a factor involving the number of fitted parameters and an estimate of the error variance. The unscaled expression above is still useful for seeing how leverage and residual size jointly determine influence.

5Autoregression

Autoregressive models use past values of a time series to predict its current value.

A zero-intercept AR(p) model is

Xt=ϕ1Xt1+ϕ2Xt2++ϕpXtp+ϵt,

where

  • Xt is the value of the time series at time t,
  • ϕ1,,ϕp are autoregressive coefficients,
  • ϵt is a white-noise error term with mean zero and constant variance.

If a nonzero intercept is desired, one can instead write

Xt=c+ϕ1Xt1++ϕpXtp+ϵt.

For simplicity, consider the zero-intercept case. Given

X1,X2,,XT,

define

Y=(Xp+1Xp+2XT)

and the lagged design matrix

Z=(XpXp1X1Xp+1XpX2XT1XT2XTp).

Let

Φ=(ϕ1ϕ2ϕp),ϵ=(ϵp+1ϵp+2ϵT).

Then the AR model can be written as

Y=ZΦ+ϵ.

Thus estimation of the AR coefficients can be viewed as a linear regression problem on lagged observations. The notation Z is used for the design matrix to avoid confusing it with the time-series variable Xt.