7 Matrix Approach to Linear Regression & Multiple Linear Regression

Multiple Linear Regression

Set Up

The model

Y=Xβ+εY=X\beta+\varepsilon

where ε∼N(0,σ2In)  ⟹  Y∼N(Xβ,σ2In)\varepsilon\sim N(\boldsymbol{0},\sigma^{2}I_{n})\implies Y\sim N(X\beta,\sigma^{2}I_{n}). Here we see XX as a fixed matrix or we condition on XX (the whole matrix).

Suppose Xn×pX_{n\times p} has full column rank.

OLS estimator for β\beta is

b=(XTX)−1XTYb=(X^TX)^{-1}X^TY

Projection matrix

H=X(XTX)−1XTH=X(X^TX)^{-1}X^T

Fitted value

Y^=HY=Xb\hat{Y}=HY=Xb

Residual

e=Y−Y^=(I−H)Ye=Y-\hat{Y}=(I-H)Y

Here are some properties:

  • eTY^=0e^T\hat{Y}=0
  • Tr(H)=p\mathrm{Tr}(H)=p.

Estimation of σ2\sigma^{2}

MSE=SSEn−p=eTen−pMSE=\frac{SSE}{n-p}=\frac{e^Te}{n-p}

MSEMSE is valid for estimating σ2\sigma^{2} because

E[MSE]=1n−pE[YT(I−H)Y]=σ2\mathbb{E}[MSE]=\frac{1}{n-p}\mathbb{E}[Y^T(I-H)Y]=\sigma^{2}

Let XX be a random vector with EX=μ,Cov(X)=Σ\mathbb{E}X=\mu,\mathrm{Cov}(X)=\Sigma, then

E[XTAX]=Tr(AΣ)+μTAμ\mathbb{E}[X^TAX]=\mathrm{Tr}(A\Sigma)+\mu^TA\mu

The one-dimension version:

E[aX2]=aV[X]+aE2[X]\mathbb{E}[aX^{2}]=a\mathbb{V}[X]+a\mathbb{E}^{2}[X]

Let Cov(X)=Σ,E[X]=μ\mathrm{Cov}(X)=\Sigma, \mathbb{E}[X]=\mu

E[XTAX]=Tr[(E[XTAX])]=E[Tr(XTAX)]=E[Tr(AXXT)]=Tr[AE(XXT)]=Tr[A(Σ+μμT)]=Tr(AΣ)+μTAμ\begin{align} \mathbb{E}[X^TAX] & = \mathrm{Tr}[(\mathbb{E}[X^TAX])] \\ & = \mathbb{E}[\mathrm{Tr}(X^TAX)] \\ & = \mathbb{E}[\mathrm{Tr}(AXX^T)] \\ & = \mathrm{Tr}[A\mathbb{E}(XX^T)] \\ & = \mathrm{Tr}[A(\Sigma+\mu \mu^T)] \\ & = \mathrm{Tr}(A\Sigma)+\mu^TA\mu \end{align}

Sampling Distribution of bb

Recall that

Y∼N(Xβ,σ2I), b=(XTX)−1XTYY\sim N(X\beta,\sigma^{2}I),\ b=(X^TX)^{-1}X^TY

So

b∼N(β,σ2(XTX)−1)b\sim N\left(\beta,\sigma^{2}(X^TX)^{-1}\right)

Replace σ2\sigma^{2} with s2=MSEs^{2}=MSE to get the estimated covariance matrix.

Gauss-Markov Theorem

Under Gauss-Markov assumptions:

  1. Linearity: the parameters are themselves linear
  2. Randomness: the data must have been randomly sampled from the population
  3. Non-Collinearity: the regressors aren’t perfectly correlated with each other
  4. Exogeneity: the regressors aren't correlated with the error term, E[ε∣X]=0\mathbb{E}[\varepsilon\mid X]=0. (给定向量还是给定整个设计矩阵?)
  5. Homoscedasticity: no matter what the values of the regressors might be, the error of the variance is constant.
    the OLS estimate for regression coefficients gives you the best linear unbiased estimate (BLUE) possible.

367

The Leverage

On one hand

HT=H=H2  ⟹  hii=eiTHei=eiTHTHei≥0H^T=H=H^{2}\implies h_{ii}=e_{i}^THe_{i}=e_{i}^TH^THe_{i}\geq 0

On the other hand,

eiTHei=hii=eiTH2ei=hii2+∑i≠jhij2  ⟹  hii≥hii2  ⟹  hii≤1e_{i}^THe_{i}=h_{ii}=e_{i}^TH^{2}e_{i}=h_{ii}^{2}+\sum _{i\ne j}h_{ij}^{2}\implies h_{ii}\geq h_{ii}^{2}\implies h_{ii}\leq 1

In conclusion we have

hii∈[0,1]h_{ii}\in [0,1]

有时间研究一下取等条件

Don't forget that

hii=∂Y^i∂Yi=∂∑j=1nhijYj∂Yih_{ii}=\frac{ \partial \hat{Y}_{i} }{ \partial Y_{i} } = \frac{ \partial \sum_{j=1}^{n} h_{ij}Y_{j} }{ \partial Y_{i} }


Recall that here we say the leverage describes the distance of XiX_{i} from the center Xˉ\bar{X}. Now we extend this concept to higher dimension.

The overall principle is to adjust the spread of each direction.

示意图:A、B 到均值的欧氏距离相同,但 A 沿着数据的主要分布方向,B 偏离了分布规律,因此 B 的马氏距离更大|421

Let (1,xiT)(1, x_{i}^T) be the ii-th row of XX and let xˉ=1n∑xi\bar{x}=\frac{1}{n}\sum x_{i}. Here we define the distance of xix_{i} from the center xˉ\bar{x}:

D(xi,xˉ)=(xi−xˉ)TΣ−1(x−xˉ)D(x_{i},\bar{x})=\sqrt{(x_{i}-\bar{x})^T\Sigma^{-1}(x-\bar{x})}

where Σ\Sigma is the sample covariance matrix. Can show that

hii=1n+D2(xi,xˉ)n−1h_{ii}=\frac1n+\frac{D^2(x_{i},\bar{x})}{n-1}

This distance measure is known as Mahalanobis Distance.

Let X=[1 Z]X=[\boldsymbol{1}\ Z], and Zc=Z−1n11TZ=(I−J)ZZ_{c}=Z-\frac{1}{n}\boldsymbol{1}\boldsymbol{1}^TZ=(I-J)Z (centralize it). Then

Σ=1n−1ZcTZc=1n−1ZT(I−J)Z\Sigma=\frac{1}{n-1}Z_{c}^TZ_{c}=\frac{1}{n-1}Z^T(I-J)Z

We hope to find the relationship between the diagonal elements of

ZΣ−1ZT and HZ\Sigma^{-1}Z^T\ \text{and}\ H

Expand HH as

[1 Z]([1 Z]T[1 Z])−1[1 Z]T=[1 Z][n1TZZT1ZTZ]−1[1 Z]T[1\ Z]\left( [1\ Z]^T[1\ Z] \right) ^{-1}[1\ Z]^T= [1\ Z] \begin{bmatrix} n & \boldsymbol{1}^TZ \\ Z^T\boldsymbol{1} & Z^TZ \end{bmatrix}^{-1} [1\ Z]^T

Recall the knowledge of Shur complement. Shur complement of nn is

ZTZ−(ZT1)n−1(1TZ)=ZT(I−J)Z=:SZ^TZ-(Z^T\boldsymbol{1})n^{-1}(\boldsymbol{1}^TZ)=Z^T(I-J)Z=:S

it is reversible iff 1∉R(Z)\boldsymbol{1}\not\in \mathcal{R}(Z), which is guaranteed. So

[n1TZZT1ZTZ]−1=[1n+zˉTS−1zˉ−zˉTS−1−S−1zˉS−1]\begin{bmatrix} n & \boldsymbol{1}^TZ \\ Z^T\boldsymbol{1} & Z^TZ \end{bmatrix}^{-1} =\begin{bmatrix} \frac1n+\bar z^TS^{-1}\bar z&-\bar z^TS^{-1}\\ -S^{-1}\bar z&S^{-1} \end{bmatrix}

therefore

hii=[1ziT][1n+zˉTS−1zˉ−zˉTS−1−S−1zˉS−1][1zi]=1n+(zi−zˉ)TS−1(zi−zˉ)h_{ii}= \begin{bmatrix} 1 & z_{i}^T \end{bmatrix} \begin{bmatrix} \frac1n+\bar z^TS^{-1}\bar z&-\bar z^TS^{-1}\\ -S^{-1}\bar z&S^{-1} \end{bmatrix} \begin{bmatrix} 1 \\ z_{i} \end{bmatrix} = \frac{1}{n}+(z_{i}-\bar{z})^TS^{-1}(z_{i}-\bar{z})

Note that S−1=Σ−1/(n−1)S^{-1}=\Sigma^{-1}/(n-1), so

hii=1n+D2(zi,zˉ)n−1h_{ii}=\frac{1}{n}+\frac{D^{2}(z_{i},\bar{z})}{n-1}

Covariance Matrix of ee

Cov(e)=Cov((I−H)Y)=σ2(I−H)\mathrm{Cov}(e)=\mathrm{Cov}((I-H)Y)=\sigma^{2}(I-H)

so

Var(ei)=σ2(1−hii)Cov(ei,ej)=−σ2hij\begin{align} \mathrm{Var}(e_{i}) & =\sigma^{2}(1-h_{ii}) \\ \mathrm{Cov}(e_{i},e_{j}) & =-\sigma^{2}h_{ij} \end{align}

Think a bit deeper: hiih_{ii} large   ⟹  \implies Var(ei)\mathrm{Var}(e_{i}) closer to 0   ⟹  \implies fitting is more stable.

Expected Mean Squares and ANOVA F-Test

Already showed that

E[MSE]=σ2\mathbb{E}[MSE]=\sigma^{2}

Let's see MSR=∥(H−J)Y∥2p−1MSR=\frac{\|(H-J)Y\|^{2}}{p-1}.

E[MSR]=1p−1E[YT(H−J)Y]=1p−1(Tr((H−J)σ2)+(Xβ)T(H−J)(Xβ))=σ2+1p−1(Xβ)T(H−J)(Xβ)\begin{align} \mathbb{E}[MSR] & = \frac{1}{p-1}\mathbb{E}[Y^T(H-J)Y] \\ & =\frac{1}{p-1}(\mathrm{Tr}((H-J)\sigma^{2})+(X\beta)^T(H-J)(X\beta)) \\ & = \sigma^{2}+\frac{1}{p-1}(X\beta)^T(H-J)(X\beta) \end{align}

Easy to see that

(Xβ)T(H−J)(Xβ)=0  ⟺  β1=β2=⋯=βp−1=0(X\beta)^T(H-J)(X\beta)=0 \iff \beta_{1}=\beta_{2}=\dots=\beta_{p-1}=0

Note that H−JH-J is a projection matrix. So

(Xβ)T(H−J)(Xβ)=0  ⟺  (H−J)Xβ=0(X\beta)^T(H-J)(X\beta)=0 \iff (H-J)X\beta=0

Because Xβ∈R(H)X\beta\in \mathcal{R}(H) and R(H)=R(H−J)⊕R(J)\mathcal{R}(H)=\mathcal{R}(H-J)\oplus \mathcal{R}(J), we have

(H−J)Xβ=0  ⟺  Xβ∈R(J)=span(1)  ⟺  β2=⋯=βp−1=0(H-J)X\beta=0 \iff X\beta\in \mathcal{R}(J)=\mathrm{span}(\boldsymbol{1}) \iff \beta_{2}=\dots=\beta_{p-1}=0

This can be used to conduct the F-test:

  • H0:H_{0}: β1=β2=⋯=βp−1=0\beta_{1}=\beta_{2}=\dots=\beta_{p-1}=0.
  • H1:H_{1}: βk≠0\beta_{k}\ne 0 for at least one kk in 1,2,…,p−11,2,\dots,p-1.

The F-statistic is

F=MSRMSE∼Fp−1,n−pF=\frac{MSR}{MSE}\sim F_{p-1,n-p}

Reject H0H_{0} if FF is large enough.

R2R^{2} and Adjusted R2R^{2}

R2=1−SSESSTR^{2}=1-\frac{SSE}{SST}

But adding regressors can always decrease SSESSE. Penalty on adding regressors needed.

Ra2=1−MSEMST=1−n−1n−p⋅SSESSTR_{a}^{2}=1-\frac{MSE}{MST}=1-\frac{n-1}{\color{red}n-p}\cdot\frac{SSE}{SST}


7 Matrix Approach to Linear Regression & Multiple Linear Regression
https://wtx17.github.io/2026/11/03/Lec-7-Matrix-Approach-to-LR-and-MLR/
作者
wtx
发布于
2026年11月3日
更新于
2026年11月6日
许可协议