9 Extra Sum of Squares & General Linear Tests

Extra Sum of Squares

Definition

Consider the model

Y∼1+X1+⋯+Xp−1Y\sim 1+X_{1}+\dots+X_{p-1}

we denote the SSR of the model as

SSR(X1,…,Xp−1)SSR(X_{1},\dots,X_{p-1})

Similarly can denote the SSE of the model as

SSE(X1,…,Xp−1)SSE(X_{1},\dots,X_{p-1})

Suppose now we have more explanatory variables Xp,…,XqX_{p},\dots,X_{q}, then the extra sum of squares is defined as

SSR(Xp,…,Xq∣X1,…,Xp−1)=SSR(X1,…,Xq)−SSR(X1,…,Xp)SSR(X_{p},\dots,X_{q}\mid X_{1},\dots,X_{p-1})=SSR(X_{1},\dots,X_{q})-SSR(X_{1},\dots,X_{p})

On the other hand, it also equals to

SSE(X1,…,Xp)−SSE(X1,…,Xq)SSE(X_{1},\dots,X_{p})-SSE(X_{1},\dots,X_{q})

The additional variation explained the newly-added variables.

3 Types of SS

In a given model, each explanatory variable can be assigned a SS.

We use a specific model

Y∼1+A+BY\sim 1+A+B

to illustrate the three types of SS.

Term Type I SS Type II SS Type III SS
AA SSR(A)SSR(A) SSR(A∣B)SSR(A \mid B) SSR(A∣B,AB)SSR(A \mid B, AB)
BB SSR(B∣A)SSR(B \mid A) SSR(B∣A)SSR(B \mid A) SSR(B∣A,AB)SSR(B \mid A, AB)
ABAB SSR(AB∣A,B)SSR(AB \mid A, B) Yates: no significant interaction is assumed SSR(AB∣A,B)SSR(AB \mid A, B)
  • Type I SS is sequential. Adding each SS can make up SSR(A,B,AB)SSR(A,B,AB). R use this as the default. So the ANOVA table in R differs with the sequence of the variables.
  • Type III SS is unique. Each SS refers to variables added last. SPSS use this as the default.
  • Type II SS is similar to type III SS, except ignoring the interaction term. Python use this as the default.
    383

For type III, testing main effects (pure AA or BB) in the presence of an interaction (ABAB) is a violation of the marginality principle. The principle roughly says that the interaction can only be considered after the main effects are add.

General Linear Test

Definition

It compares two models

  • Full model, and
  • Reduced model
    where the full model considers all explanatory variables and the reduced model is the one when the null hypothesis holds.

The reduced model is nested in the full model. So the null hypothesis should be like

H0:Rβ=tH_{0}: R\beta=t

where RR is a constant matrix with full row rank and tt is a constant vector. Here are some examples:

  • β1=0\beta_{1}=0
  • β1=β2=β3=0\beta_{1}=\beta_{2}=\beta_{3}=0
  • β1+β3=7,β1−β7=13\beta_{1}+\beta_{3}=7,\beta_{1}-\beta_{7}=13

The test statistic is

F=[SSE(R)−SSE(F)]/(dfE(R)−dfE(F))SSE(F)/dfE(F)F = \frac{[SSE(R)-SSE(F)]/(df_{E}(R)-df_{E}(F))}{SSE(F)/df_{E}(F)}

It follows Fq,n−pF_{q,n-p} under H0H_{0}, where

q=dfE(R)−dfE(F)=rank(R)n−p=dfE(F)\begin{align} q & =df_{E}(R)-df_{E}(F)=\mathrm{rank}(R)\\ n-p & =df_{E}(F) \end{align}

We have to know two lemmas:

The first is

SSE(β~)−SSE(β^OLS)=(β^−β~)TXTX(β^−β~)SSE(\tilde{\beta})-SSE(\hat{\beta}^{OLS})=(\hat{\beta}-\tilde{\beta})^TX^TX(\hat{\beta}-\tilde{\beta})

(Easy to show)

The second is

argmin⁡a:Ra=taTXTXa=(XTX)−1RT(R(XTX)−1RT)−1t\operatorname*{argmin}_{a:Ra=t}a^TX^TXa=(X^TX)^{-1}R^T(R(X^TX)^{-1}R^T)^{-1}t

(Constrained quadratic optimization)

With these lemmas, we have

SSE(R)−SSE(F)=(Rβ^−t)T(R(XTX)−1RT)−1(Rβ^−t)SSE(R)-SSE(F)=(R\hat{\beta}-t)^T(R(X^TX)^{-1}R^T)^{-1}(R\hat{\beta}-t)

With lemmas in Lec8-MLR-Example-and-Inference › The Fundamental Theorems, we further have

SSE(R)∼χq2SSE(R)\sim \chi^{2}_{q}

under H0H_{0}.

We already have

SSE(F)∼χn−p2SSE(F)\sim \chi^{2}_{n-p}

The randomness of SSE(R)−SSE(F)SSE(R)-SSE(F) is from Rβ^=R(XTX)−1XTYR\hat{\beta}=R(X^TX)^{-1}X^TY, while SSE(F)SSE(F) is from (I−X(XTX)−1XT)Y(I-X(X^TX)^{-1}X^T)Y. Can show that these two are uncorrelated, thus independent. So SSE(R)−SSE(F)⊥SSE(F)SSE(R)-SSE(F)\perp SSE(F). Therefore,

F=[SSE(R)−SSE(F)]/(dfE(R)−dfE(F))SSE(F)/dfE(F)∼Fq,n−pF = \frac{[SSE(R)-SSE(F)]/(df_{E}(R)-df_{E}(F))}{SSE(F)/df_{E}(F)}\sim F_{q,n-p}

under H0H_{0}.

Special Cases

If H0H_{0} is βk=0\beta_{k}=0, it is equivalent to t-test. See here.

Intuitively, the F statistic and t statistic both measure the prediction capability of the pure part of Xk.X_{k}. One sees the reduction of SSESSE and the other sees the magnitude of bkb_{k}.

If H0H_{0} is β1=⋯=βp−1=0\beta_{1}=\dots=\beta_{p-1}=0, it is equivalent to ANOVA F-test.

Notes on Interpreting the GLT Results

We often looking to "cannot to reject" when performing a test like this – our goal is to eliminate unnecessary variables. But we have to consider the probability of "fail to reject" which is 1−power1-\mathrm{power}. So we have to consider power. See here.

“总之就是,不要轻易丢变量。”

Coefficients of Partial Determination

Definition

It measures the amount of remaining variation explained by a variable given other variables already in the model. The formula is

RYk∣1,…,k−1,k+1,…,q2=SSR(Xk∣X−k)SSE(X−k)R^{2}_{Yk\mid 1,\dots,k-1,k+1,\dots, q}= \frac{SSR(X_{k}\mid X_{-k})}{SSE(X_{-k})}

where X−k=(X1,…,Xk−1,Xk+1,…,Xq)X_{-k}=(X_{1},\dots,X_{k-1},X_{k+1},\dots,X_{q}). Usually use η2\eta^{2} to denote it.

Look at the illustration below. RY2∣12=BB+DR^{2}_{Y2\mid 1}=\frac{B}{B+D}.
218

Relationships with R2R^{2}

Run

Y∼1+X1+⋯+Xk−1+Xk+1+⋯+XqY\sim 1+X_{1}+\dots+X_{k-1}+X_{k+1}+\dots+X_{q}

and get the residuals ee.

Run

Xk∼1+X1+⋯+Xk−1+Xk+1+⋯+XqX_{k}\sim 1+X_{1}+\dots+X_{k-1}+X_{k+1}+\dots+X_{q}

and get the residuals rr.

Then run

e∼re\sim r

and get R2R^{2} of this model.

Then we have

RYk∣−k2=R2R^{2}_{Y k\mid -k}=R^{2}

This is saying that the partial R2R^{2} is the normal R2R^{2} from a simple linear regression. And we will show later that R2R^{2} from a simple linear regression is just the squared correlation between the two variables.

Run e∼re\sim r to get the residual u=e−bru=e-br (no intercept because eˉ=rˉ=0\bar{e}=\bar{r}=0), where b=rerse/srb=r_{er}s_{e}/s_{r} (r∗∗r_{**} is sample correlation, s∗2s^{2}_{*} is sample variance).

RYk∣−k2=SSE(X−k)−SSE(Xall)SSE(X−k)R^{2}_{Y k\mid -k}=\frac{SSE(X_{-k})-SSE(X_{all})}{SSE(X_{-k})}

By FWL theorem, we have

SSE(Xall)=uTu\color{red} SSE(X_{all})=u^Tu

Plug in u=e−bru=e-br we get

uTu=⋯=(n−1)(se2−rer2se2)u^Tu=\dots=(n-1)(s^{2}_{e}-r^{2}_{er}s^{2}_{e})

Note that SSE(X−k)=(n−1)se2SSE(X_{-k})=(n-1)s^{2}_{e}, so RYk∣−k2=rer2R^{2}_{Y k\mid -k}=r^{2}_{er}.

We will show that rer2=R2r^{2}_{er}=R^{2} afterwards.

Partial Correlation

Here we give the formal definition. Suppose there are two r.v.s X,YX,Y and a random vector CC whose components are linear independent (This ensures that V[C]\mathbb{V}[C] is reversible). The linear projection of XX and YY on CC are X\mathcal{X} and Y\mathcal{Y} respectively. Then the partial correlation between XX and YY given CC is defined as

rXY⋅C=Corr(X−X,Y−Y)r_{XY\cdot C}=\mathrm{Corr}(X-\mathcal{X},Y-\mathcal{Y})

As in OLS, we are interested in the partial correlation between the dependent variable YY and a specific independent variable XkX_{k} given all other independent variables, i.e. rYk∣−kr_{Yk\mid -k}. Below we talk about the partial correlation obtained from sample.
422

Can show that

RYk∣−k2=rYk⋅−k2R^{2}_{Y k\mid -k}=r^{2}_{Y k\cdot -k}

In simple linear regression Y∼XY\sim X, we have

R2=SSRSST=sY^2sY2R^{2}=\frac{SSR}{SST}=\frac{s^{2}_{\hat{Y}}}{s^{2}_{Y}}

and

Y^=b1X=rYXsYsXX\hat{Y}=b_{1}X=\frac{r_{YX}s_{Y}}{s_{X}}X

thus

sY^2=rYX2sY2s^{2}_{\hat{Y}}=r^{2}_{YX}s^{2}_{Y}

so finally

R2=rYX2R^{2}=r_{YX}^{2}

For example, if 0<rYk∣−k<rYk0<r_{Yk\mid -k}<r_{Yk}, then the interpretation is that all other variables partly explains the correlation between XkX_{k} and YY.222
We will soon talk about the case when 0<rYk<rYk∣−k0<r_{Yk}<r_{Yk\mid -k} in Connection of Cor and Partial Cor.

Standardized Regression

Why Needed

  • Units of β1\beta_{1} and β2\beta_{2} are different, making direct comparison implausible.
  • When X1X_{1} and X2X_{2} are dramatically different in magnitudes, the matrix computation will have numerical problems.

Definition

The original model is

Yi=β0+β1Xi1+⋯+βp−1Xi,p−1+εiY_{i} = \beta_{0}+\beta_{1}X_{i 1}+\dots+\beta_{p-1}X_{i,p-1}+\varepsilon_{i}

with some assumptions.

Let Yˉ\bar{Y} be the sample mean of YY, Xˉk\bar{X}_{k} be the sample mean of XkX_{k}, sY,sXks_{Y}, s_{X_{k}} be the sample standard deviation of YY and XkX_{k}. We do the following transformation:

Yi−YˉsY=1sY(β0+β1Xi1+⋯+βp−1Xi,p−1+εi−β0−β1Xˉ1−⋯−βp−1Xˉp−1−εˉ)=1sY(β1(Xi1−Xˉ1)+⋯+βp−1(Xi,p−1−Xˉp)+(εi−εˉ))=β1sX1sY⋅Xi1−Xˉ1sX1+⋯+βp−1sXp−1sY⋅Xi,p−1−Xˉp−1sXp−1+εi−εˉsY\begin{align} \frac{Y_{i}-\bar{Y}}{s_{Y}} & =\frac{1}{s_{Y}}(\beta_{0}+\beta_{1}X_{i 1}+\dots+\beta_{p-1}X_{i,p-1}+\varepsilon_{i}-\beta_{0}-\beta_{1}\bar{X}_{1}-\dots-\beta_{p-1}\bar{X}_{p-1}-\bar{\varepsilon}) \\ & = \frac{1}{s_{Y}}(\beta_{1}(X_{i1}-\bar{X}_{1})+\dots+\beta_{p-1}(X_{i,p-1}-\bar{X}_{p})+(\varepsilon_{i}-\bar{\varepsilon})) \\ & = \frac{\beta_{1}s_{X_{1}}}{s_{Y}}\cdot \frac{X_{i1}-\bar{X}_{1}}{s_{X_{1}}}+\dots+\frac{\beta_{p-1}s_{X_{p-1}}}{s_{Y}}\cdot \frac{X_{i,p-1}-\bar{X}_{p-1}}{s_{X_{p-1}}}+ \frac{\varepsilon_{i}-\bar{\varepsilon}}{s_{Y}} \end{align}

Furthermore, we divide both sides by n−1\sqrt{n-1}:

Yi−YˉsYn−1=β1sX1sY⋅Xi1−Xˉ1sX1n−1+⋯+βp−1sXp−1sY⋅Xi,p−1−Xˉp−1sXp−1n−1+εi−εˉsYn−1\frac{Y_{i}-\bar{Y}}{s_{Y}\sqrt{n-1}}=\frac{\beta_{1}s_{X_{1}}}{s_{Y}}\cdot \frac{X_{i1}-\bar{X}_{1}}{s_{X_{1}}\sqrt{n-1}}+\dots+\frac{\beta_{p-1}s_{X_{p-1}}}{s_{Y}}\cdot \frac{X_{i,p-1}-\bar{X}_{p-1}}{s_{X_{p-1}}\sqrt{n-1}}+ \frac{\varepsilon_{i}-\bar{\varepsilon}}{s_{Y}\sqrt{n-1}}

This is the final model.

This is called the Correlation Transformation, which bring the convenience that is

Y∗TXk∗=∑i=1N(Yi−YˉsYn−1)(Xik−XˉksXkn−1)=∑i=1N(Yi−Yˉ)(Xik−Xˉk)∑i=1N(Yi−Yˉ)2⋅∑i=1N(Xik−Xˉk)2Y^{*T}X_{k}^*=\sum_{i=1}^{N} \left( \frac{Y_{i}-\bar{Y}}{s_{Y}\sqrt{n-1}} \right) \left( \frac{X_{ik}-\bar{X}_{k}}{s_{X_{k}}\sqrt{n-1}}\right)= \frac{\sum_{i=1}^{N} (Y_{i}-\bar{Y})(X_{i k}-\bar{X}_{k})}{\sqrt{\sum_{i=1}^{N} (Y_{i}-\bar{Y})^{2}}\cdot \sqrt{\sum_{i=1}^{N} (X_{i k}-\bar{X}_{k})^{2}}}

which is exactly rYkr_{Yk}, the sample correlation between YY and XkX_{k}. We define

rYX=X∗TY∗=[rY1⋮rY,p−1]r_{YX}=X^{*T}Y^{*}= \begin{bmatrix} r_{Y1} \\ \vdots \\ r_{Y,p-1} \end{bmatrix}

Similarly, can show that

X∗TX∗=[1r12…r1,p−1r211…r2,p−1⋮⋮⋱⋮rp−1,1rp−1,2…1]=:rXXX^{*T}X^*= \begin{bmatrix} 1 & r_{12} & \dots & r_{1,p-1} \\ r_{21} & 1 & \dots & r_{2,p-1} \\ \vdots & \vdots & \ddots & \vdots \\ r_{p-1,1} & r_{p-1,2} & \dots & 1 \end{bmatrix}=: r_{X X}

An example of application is here.

Though it brings convenience, we should bear it mind that the error terms εi−εˉsYn−1\frac{\varepsilon_{i}-\bar{\varepsilon}}{s_{Y}\sqrt{n-1}} are not i.i.d. anylonger.

Some notes:

  • Any quantities with units such as SS in ANOVA table change
  • Scale-free quantities such as R2R^{2} and η2\eta^{2} don't change.
  • β^0∗\hat{\beta}^{*}_{0} must be 0, it's an algebraic property.

Connection of Cor and Partial Cor

We have

RY2∣12=(rY2∣1)2=(rY2−r12rY1)2(1−rY12)(1−r122)R^{2}_{Y 2\mid 1}=(r_{Y 2\mid 1})^{2}=\frac{(r_{Y 2}-r_{12}r_{Y 1})^{2}}{(1-r_{Y 1}^{2})(1-r_{12}^{2})}

The proof is here.

When rY1≈0r_{Y1}\approx 0, we have rY2∣12≈rY221−r122≥rY22r_{Y2\mid 1}^{2}\approx \frac{r_{Y 2}^{2}}{1-r_{12}^{2}}\geq r_{Y 2}^{2}.

Can extend to more variables:
336

Suppressor Variables

If SSR(X2∣X1)>SSR(X2)SSR(X_{2}\mid X_{1})>SSR(X_{2}) then X1X_{1} is called a suppressor variable of X2X_{2}.

The general idea is that a suppressor variable will suppress irrelevant variance of other independent variables. We can say X1X_{1} suppresses the noise (the part that has no prediction ability of YY) in X2X_{2}.
155

新记号:SSR(X1∣X2)SSR(X_{1}\mid X_{2}).

Add One Variable at a Time: Type I SS

  • squential
  • 相加等于总体
  • R 的 ANOVA 默认输出

Type III SS

  • 最后一个进模型
  • 等价于上节课讲的,对单个系数的 t-test
  • Unique
  • SSPS

Type II SS

  • 跟 Type III SS 一样,除了
  • 假设没有交互效应。 不知道放不放 A,为啥要放 AB?不考虑 SSR(A∣B,AB)SSR(A\mid B,AB).
    • 低阶效应比高阶效应重要,高阶已进模型,低阶必进
  • Python

fail to reject 是我们想要的,我们不想要那么多变量。

  • 注意样本量!power=正确拒绝的概率
  • 别轻易扔变量

偏 R2R^{2}

  • YY 纯净部分和 XkX_{k} 纯净部分之间的 R2R^{2}.

偏相关系数

标准化回归

  • 为啥要除以 n−1\sqrt{n-1}?
  • 偏相关系数与相关系数
  • 抑制变量,抑制 XkX_{k} 的噪音(与 YY 无关的部分)

9 Extra Sum of Squares & General Linear Tests
https://wtx17.github.io/2026/11/17/Lec9-Extra-SS-and-GLT/
作者
wtx
发布于
2026年11月17日
更新于
2026年12月2日
许可协议