The Gram Matrix and Normal Equations

The orthogonality condition

Good notation translations to know for economists. (These will show up in the article)

(controls,econometrics)(\text{controls}, \text{econometrics})

c=β\pmb c = \pmb \beta

p=X′y\pmb p = X'y

A=XA = X

x=y\pmb x = \pmb y

The Projection Theorem

We'll take as a given that the projection theorem is true.

Suppose SS is a vector space and let T={p1,…,pm}⊂ST = \{\pmb p_1, \dots, \pmb p_m \} \subset S. Furthermore, let V=span(T)V = \text{span}(T).

For relevance to least squares, consider x=x^+e=∑i=1mcici+e\pmb x = \hat {\pmb x} + \pmb e = \sum_{i=1}^m c_i \pmb c_i + \pmb e. We want to minimize e\pmb e.

The projection theorem states that for x∈S\pmb x \in S, the solution to

min⁡c1,…,cm  ∥e∥=min⁡c1,…,cm∥x−∑i=1mcipi∥\begin{align} \min_{c_1, \dots, c_m}\; \lVert\pmb e\rVert = \min_{c_1, \dots, c_m} \lVert \pmb x - \sum_{i=1}^mc_i\pmb p_i\rVert \end{align}

is obtained when e⊥span(T)\pmb e \perp \text{span}(T) which is equivalent to ⟨e,v⟩=0\langle \pmb e ,\pmb v\rangle = 0 for all v∈span(T)\pmb v \in \text{span}(T)

The Grammian

The above problem may be more familiar if we write x=x^+e\pmb x = \hat {\pmb x} + \pmb e where we've defined x^=∑i=1mcipi\hat{\pmb x}= \sum_{i=1}^mc_i\pmb p_i.

Let v∈span(T)\pmb v \in \text{span}(T). Invoking the projection theorem, we know that our solution must satisfy

⟨e,v⟩=⟨x−x^,v⟩=⟨x,v⟩−⟨x^,v⟩=0  ⟹  ⟨x,v⟩=⟨x^,v⟩=⟨∑i=1mcipi,v⟩=∑i=1mci⟨pi,v⟩=c1⟨p1,v⟩+⋯+cm⟨pm,v⟩\begin{align*} \langle \pmb e, \pmb v\rangle &= \langle \pmb x - \hat{\pmb x}, \pmb v\rangle \\ &= \langle \pmb x, \pmb v \rangle - \langle \hat{\pmb x} , \pmb v \rangle \\ &= 0 \\ \implies \langle \pmb x, \pmb v \rangle &= \langle \hat{\pmb x} , \pmb v \rangle \\ &= \left\langle \sum_{i=1}^mc_i\pmb p_i, \pmb v \right\rangle \\ &= \sum_{i=1}^mc_i\left\langle \pmb p_i, \pmb v \right\rangle \\ &= c_1\langle \pmb p_1, \pmb v\rangle + \dots + c_m\langle \pmb p_m, \pmb v\rangle \end{align*}

Therefore we have that c1⟨p1,v⟩+⋯+cm⟨pm,v⟩=⟨x,v⟩c_1\langle \pmb p_1, \pmb v\rangle + \dots + c_m\langle \pmb p_m, \pmb v\rangle = \langle \pmb x, \pmb v \rangle for all v∈span(T)\pmb v \in \text{span}(T).

Clearly p1,…,pm∈span(T)\pmb p_1, \dots, \pmb p_m \in \text{span}(T). Consider substituting each p\pmb p in for v\pmb v to generate the following mm equation.

c1⟨p1,p1⟩+⋯+cm⟨pm,p1⟩=⟨x,p1⟩⋮c1⟨p1,pm⟩+⋯+cm⟨pm,pm⟩=⟨x,pm⟩\begin{align*} c_1\langle \pmb p_1, \pmb p_1\rangle + \dots + c_m\langle \pmb p_m, \pmb p_1\rangle &= \langle \pmb x, \pmb p_1\rangle \\ \vdots \\ c_1\langle \pmb p_1, \pmb p_m\rangle + \dots + c_m\langle \pmb p_m, \pmb p_m\rangle &= \langle \pmb x, \pmb p_m\rangle \end{align*}

These are known as the normal equations. They can be written in matrix form as:

[⟨p1,p1⟩…⟨pm,p1⟩⋮⋱⋮⟨p1,pm⟩…⟨pm,pm⟩]⏟Grammian[c1⋮cm]=[⟨x,p1⟩⋮⟨x,pm⟩]⏟Cross CorrelationRc=p\begin{align*} \underbrace{\begin{bmatrix} \langle \pmb p_1, \pmb p_1 \rangle & \dots & \langle \pmb p_m, \pmb p_1 \rangle \\ \vdots & \ddots & \vdots \\ \langle \pmb p_1, \pmb p_m \rangle & \dots & \langle \pmb p_m, \pmb p_m \rangle \end{bmatrix}}_{\text{Grammian}} \begin{bmatrix}c_1 \\ \vdots \\ c_m\end{bmatrix} &= \underbrace{\begin{bmatrix} \langle \pmb x, \pmb p_1 \rangle \\ \vdots \\ \langle \pmb x, \pmb p_m\rangle \end{bmatrix}}_{\text{Cross Correlation}}\\[25pt] R \pmb c &= \pmb p \end{align*}

RR is the Gram matrix (aka the Grammian). It's a Hermitian, positive definite matrix.

Solution to Norm Minimization

Recall that x=x^+e\pmb x = \hat{\pmb x} + \pmb e where x^=∑i=1mcipi\hat{\pmb x} = \sum_{i=1}^mc_i\pmb p_i. This can be written as x^=Ac\hat{\pmb x} = A \pmb c where A=[p1…pm]A = \begin{bmatrix}\pmb p_1 & \dots & \pmb p_m\end{bmatrix} and c=[c1…cm]T\pmb c = \begin{bmatrix}c_1 & \dots & c_m \end{bmatrix}^T. Solving for c\pmb c from the normal equations we have:

c=R−1p\begin{align*} \pmb c = R^{-1}\pmb p \end{align*}

Therefore

x^=Ac=AR−1p\begin{align*} \hat{\pmb x } &= A\pmb c \\ &= AR^{-1}\pmb p \end{align*}

Inner Products

Weighted Least Squares

Assume we're working in a finite dimensional vector space (i.e. mm is finite).

Every inner product can be written as ⟨x,y⟩=yHWx\langle \pmb x , \pmb y \rangle = \pmb y^H W \pmb x where WW is a positive definite weighting matrix.

Then starting from the top:

Rc=p[⟨p1,p1⟩…⟨pm,p1⟩⋮⋱⋮⟨p1,pm⟩…⟨pm,pm⟩][c1⋮cm]=[⟨x,p1⟩⋮⟨x,pm⟩][p1HWp1…p1HWpm⋮⋱⋮pmHWp1…pmHWpm][c1⋮cm]=[p1HWx⋮pmHWx][p1H⋮pmH]W[p1…pm][c1⋮cm]=[p1H⋮pmH]W[x⋮x]\begin{align*} R \pmb c &= \pmb p \\[8pt] \begin{bmatrix} \langle \pmb p_1, \pmb p_1 \rangle & \dots & \langle \pmb p_m, \pmb p_1 \rangle \\ \vdots & \ddots & \vdots \\ \langle \pmb p_1, \pmb p_m \rangle & \dots & \langle \pmb p_m, \pmb p_m \rangle \end{bmatrix} \begin{bmatrix}c_1 \\ \vdots \\ c_m\end{bmatrix} &= \begin{bmatrix} \langle \pmb x, \pmb p_1 \rangle \\ \vdots \\ \langle \pmb x, \pmb p_m\rangle \end{bmatrix} \\[25pt] \begin{bmatrix}\pmb p_1^H W \pmb p_1 & \dots & \pmb p_1^H W\pmb p_m \\ \vdots & \ddots & \vdots \\ \pmb p_m^H W\pmb p_1 & \dots & \pmb p_m^H W\pmb p_m\end{bmatrix} \begin{bmatrix}c_1 \\ \vdots \\ c_m\end{bmatrix} &= \begin{bmatrix} \pmb p_1^H W \pmb x \\ \vdots \\ \pmb p_m^H W \pmb x \end{bmatrix} \\[25pt] \begin{bmatrix}\pmb p_1^H \\ \vdots \\\pmb p_m^H\end{bmatrix} W \begin{bmatrix}\pmb p_1 & \dots & \pmb p_m\end{bmatrix}\begin{bmatrix}c_1 \\ \vdots \\ c_m\end{bmatrix} &= \begin{bmatrix}\pmb p_1^H \\ \vdots \\\pmb p_m^H\end{bmatrix} W \begin{bmatrix}\pmb x \\ \vdots \\ \pmb x\end{bmatrix} \end{align*}

Define A=[p1…pm]A = \begin{bmatrix}\pmb p_1 & \dots & \pmb p_m\end{bmatrix} and we've now manipulated the generalized normal equations to the normal normal equations for weighted least squares.

AHWAc=AHWxRc=p\begin{align*} A^H W A \pmb c &= A^HW \pmb x \\ R \pmb c &= \pmb p \end{align*}

When W=IW=I we have the normal equations for OLS.

Other Inner products

There are many inner products that we could consider. For example, the inner product could be the expected value or it could be the integral of the basis vectors along some interval when our spanning set are functions instead of discrete data.

Remember that the normal equations tell us a necessary and sufficient condition for when our error vector will be perpendicular to the spanning set, and by the projection theorem, this is when the induced norm is minimized.

Minimum Error

Let's write the solution to the minimum error in a few forms that are useful.

∥emin⁡∥2=∥x−x^∥2=⟨x−x^,x−x^⟩=⟨x,x⟩−⟨x,x^⟩−⟨x^,x⟩+⟨x^,x^⟩=⟨x,x⟩−⟨x^+e,x^⟩−⟨x^,x^+e⟩+⟨x^,x^⟩=⟨x,x⟩−⟨x^,x^⟩−⟨e,x^⟩⏟0−⟨x^,x^⟩−⟨x^,e⟩⏟0+⟨x^,x^⟩=⟨x,x⟩−⟨x^,x^⟩=∥x∥2−∥x^∥2\begin{align*} \lVert \pmb e_{\min} \rVert^2 &= \lVert \pmb x - \hat {\pmb x} \rVert^2 \\ &= \langle \pmb x - \hat {\pmb x} , \pmb x - \hat {\pmb x} \rangle \\ &= \langle \pmb x, \pmb x \rangle - \langle \pmb x, \hat{ \pmb x} \rangle - \langle \hat{\pmb x}, \pmb x \rangle + \langle \hat{\pmb x }, \hat{\pmb x } \rangle \\ &= \langle \pmb x, \pmb x \rangle - \langle \hat{\pmb x} + \pmb e, \hat{ \pmb x} \rangle - \langle \hat{\pmb x}, \hat{\pmb x} + \pmb e \rangle + \langle \hat{\pmb x }, \hat{\pmb x } \rangle \\ &= \langle \pmb x, \pmb x \rangle - \langle \hat{\pmb x}, \hat{ \pmb x} \rangle - \underbrace{\langle \pmb e, \hat{ \pmb x} \rangle}_{0} - \langle \hat{\pmb x}, \hat{\pmb x} \rangle - \underbrace{\langle \hat{\pmb x} , \pmb e \rangle}_0 + \langle \hat{\pmb x }, \hat{\pmb x } \rangle \\ &= \langle \pmb x , \pmb x \rangle - \langle \hat {\pmb x}, \hat {\pmb x} \rangle \\ &= \lVert \pmb x \rVert^2 - \lVert \hat {\pmb x} \rVert^2 \end{align*}

Let the inner product be characterized by any arbitrary positive definite weighting matrix.

∥x^∥2=∥Ac∥2=⟨Ac,Ac⟩=cH(AHWA)c=cHRc=cHp=pHR−1p=xHWHA(AHWA)−1AHWx\begin{align*} \lVert \hat{\pmb x} \rVert^2 &= \lVert A \pmb c \rVert^2 \\ &= \langle A \pmb c, A \pmb c \rangle \\ &= \pmb c^H (A^HWA) \pmb c \\ &=\pmb c^H R \pmb c \\ &=\pmb c^H \pmb p \\ &= \pmb p^H R^{-1}\pmb p \\ &= \pmb x^H W^H A (A^H W A)^{-1} A^H W \pmb x \end{align*}

Therefore

∥emin⁡∥2=∥x∥2−∥x^∥2=xHWx+xHWHA(AHWA)−1AHWx=xH(W−WHA(AHWA)−1AHW)x=xHMx\begin{align*} \lVert \pmb e_{\min} \rVert^2 &= \lVert \pmb x \rVert^2 - \lVert \hat {\pmb x} \rVert^2 \\ &= \pmb x^H W \pmb x + \pmb x^H W^H A (A^H W A)^{-1} A^H W \pmb x \\ &= \pmb x^H(W - W^H A (A^H W A)^{-1} A^H W)\pmb x \\ &= \pmb x^HM \pmb x \end{align*}

Consider,

M2=(W−WHA(AHWA)−1AHW)(W−WHA(AHWA)−1AHW)=WW−WWHA(AHWA)−1AHW−WHA(AHWA)−1AHW+WHA(AHWA)−1AHWWHA(AHWA)−1AHW\begin{align*} M^2 &= (W - W^H A (A^H W A)^{-1} A^H W)(W - W^H A (A^H W A)^{-1} A^H W) \\ &= WW - WW^H A (A^H W A)^{-1} A^H W - W^H A (A^H W A)^{-1} A^H W + W^H A (A^H W A)^{-1} A^H W W^H A (A^H W A)^{-1} A^H W \end{align*}

Which clearly doesn't reduce to MM. Therefore the residual maker for weighted least squares is, in general, not a projection matrix. However if W=IW=I then the residual maker is a projection matrix.