6 Remedies and Miscellaneous Topics

More Diagnostics for Residuals

Review Residual Plots

Should do EDA first. Use

1
scatter.smooth(X,Y)

to get a smoothed curve fit to see the relation ship between XX and YY.

Let see some examples:

  1. No obvious violation
  2. Nonlinearity. Because at some XX the residuals are all negative or positive.
  3. Non-constant variance. Note that the residual plot below uses absolute residual as the y-label, aiming to see the scale of residuals.

Built-in diagnostic plots in R

1
2
reg <- lm(hours ~ lotsize, data=toluca)
plot(reg)

R will show four diagnostic plots one by one:

  1. Residuals vs Fitted
  2. Normal Q-Q
  3. Scale-Location
  4. Residuals vs Leverage

Points with numbers next to them in each plot are extreme values. The numbers are the index of them, letting us to check the original data.

Residuals vs Fitted

  • Why Y^\hat{Y}? To combine all explanatory variables' influences, easy to move to multiple linear regression.
  • Used to check if the residuals have non-linear patterns.
  • It’s good if residuals equally spread around a horizontal line without distinct patterns.

Normal Q-Q

  • Used to check if the residuals are normally distributed.
  • It’s good if residuals are lined well on the straight dashed line.

Standardized residual is defined as

eis1−hii\frac{e_{i}}{s\sqrt{1-h_{ii}}}

where hii=∂Y^i∂Yi=1n+(Xi−Xˉ)2Sxxh_{ii}= \frac{\partial \hat{Y}_{i}}{\partial Y_{i}}=\frac{1}{n}+ \frac{(X_{i}-\bar{X})^{2}}{S_{x x}}, the leverage. It will be discussed in the next lecture.

Note that

V[ei∣X]=(1−hii)σ2\mathbb{V}[e_{i}\mid \boldsymbol{X}] = (1-h_{ii})\sigma^{2}

The reason why standardized residual is used is that eie_{i} are not i.i.d. so they cannot be directly used to delegate the real εi\varepsilon_{i}. Pre-process needed.

Scale-Location

  • It shows if residuals are spread equally along the ranges of predictors
  • Check the assumption of equal variance (homoscedasticity)
  • It’s good if you see a horizontal line with equally (randomly) spread points

Residuals vs Leverage

红色虚线是 Cook's distance 的等值线

Leverage, also known as the observation self-sensitivity or self-influence

hii=∂Y^i∂Yi=1n+(Xi−Xˉ)2Sxx∈[0,1]h_{ii}=\frac{\partial \hat{Y}_{i}}{\partial Y_{i}}=\frac{1}{n}+ \frac{(X_{i}-\bar{X})^{2}}{S_{x x}}\in [0,1]

For design matrix Xn×pX_{n\times p}, s2=eTen−ps^{2}=\frac{e^Te}{n-p}. Cook's distance is defined as

Di=∑j=1N(Y^j−Y^j(−i))2ps2=ei2ps2⋅hii(1−hii)2D_{i}=\frac{\sum_{j=1}^{N} (\hat{Y}_{j}-\hat{Y}_{j(-i)})^{2}}{ps^{2}}=\frac{e_{i}^{2}}{ps^{2}}\cdot \frac{h_{ii}}{(1-h_{ii})^{2}}

where Y^j(−i)\hat{Y}_{j(-i)} is the fitted response value obtained when excluding the ii-th observation. It measures the influence of ii-th case on all predicted values.

给定 hiih_{ii} 和 DiD_{i},可以解出标准化残差的平方,故可以画出两条对称的等值线。

F-Test for Lack of Fit

When we have repeat observations at various values of XX, the error term will be partitioned into pure error (error within replicates) and a lack of fit error.

412

H0:There is no lack of fit in the regression modelH1:o.w.\begin{align} H_0 & : \text{There is no lack of fit in the regression model} \\ H_{1} & : \text{o.w.} \end{align}

Use GLT, the basic idea is to compare two models -- the full one and the reduced one. Then here comes the question, what are the two models?

Suppose there are cc different observed values of XiX_{i}: x1,…,xcx_{1},\dots,x_{c}. So there are cc groups, and within each group ii, there are nin_{i} observations. Let YijY_{ij} be the jj-th response in the ii-th group.

If H0H_{0} holds, then the mean response μi=β0+β1Xi\mu_{i}=\beta_{0}+\beta_{1}X_{i}. The reduced model is

Yij=β0+β1Xi+εijY_{ij}=\beta_{0}+\beta_{1}X_{i}+\varepsilon_{ij}

Run regression and get SSE(R)SSE(R). Its df is n−2n-2.

Suppose that XiX_{i} can take mm values x1,…,xmx_{1},\dots,x_{m}. Then the full model is

Yij=μi+εijY_{ij}=\mu_{i}+\varepsilon_{ij}

Run regression and get SSE(F)=SSPESSE(F)=SSPE (Pure Error). Note that this model has as many parameters as the number of the groups. So its df is n−cn-c.

And we can get

F=[SSE(R)−SSE(F)]/(dfER−dfEF)SSE(F)/dfEFF=\frac{[SSE(R)-SSE(F)]/(df_{ER}-df_{EF})}{SSE(F)/df_{EF}}

There is a relationship

SSE=SSPE+SSLFSSE=SSPE+SSLF

Let's Have a Deeper Look at DF (Cont'd)

Look at this before going on.

Remember that SSE=∥Y^−Y∥2=∥(I−P)Y∥2SSE=\|\hat{Y}-Y\|^{2}=\|(I-P)Y\|^{2}. Below we show (I−P)Y(I-P)Y can continue to be divided into two orthogonal vectors.

Let Gij=I(Xi=j), j=1,..,cG_{ij}=I(X_{i}=j),\ j=1,..,c. Then there is another design matrix

Z=[Gij]n×cZ= \begin{bmatrix} G_{ij} \end{bmatrix}_{n\times c}

The full model can be written as

Y=Zμ+εY=Z\mu+\varepsilon

note that there is not an all-one column in ZZ, and R(P)⊆R(PZ)\mathcal{R}(P)\subseteq \mathcal{R}(P_{Z}) (there exists a matrix AA satisfying AZ=XAZ=X) where PZP_{Z} is the projection matrix of ZZ.

Rewrite (I−P)Y(I-P)Y as

(I−P)Y=(I−PZ)Y+(PZ−P)Y(I-P)Y=(I-P_{Z})Y+(P_{Z}-P)Y

We can verify that R(I−P)=R(I−PZ)⊕R(PZ−P)\mathcal{R}(I-P)=\mathcal{R}(I-P_{Z})\oplus \mathcal{R}(P_{Z}-P). The core is R(P)⊆R(PZ)\mathcal{R}(P)\subseteq \mathcal{R}(P_{Z}).

Note that

∥(I−PZ)Y∥2=SSPE, ∥(PZ−P)Y∥2=SSLF\|(I-P_{Z})Y\|^{2}=SSPE,\ \|(P_{Z}-P)Y\|^{2}=SSLF

Remedies

Nonlinear Relationships

Do transformations like log⁡,exp⁡,\log,\exp, etc. Then we may get linear relationship. But many of the times, such transformations may not exist. Then, nonlinear regression analysis is required.

Non-Constant Variance

Use a weighted analysis.

Box-Cox Transformations

  • Also called power transformations.
  • Designed for strictly positive responses.
  • Adjust for non-Normality and non-constant variance
  • Y∗=(Yλ−1)/λY^{*}=(Y^{\lambda}-1)/\lambda.

Putting it simple, in order to find the best λ\lambda, we can fix other parameters and optimize SSE(λ)SSE(\lambda) only.

Why we concern the confidence interval:

  • Interpretability
  • Check if 1 lies in the CI -- that means a linear relationship cannot be rejected.

Other Topics

X∼YX\sim Y and Y∼XY\sim X, two fitted lines. Their relationship is: the ratio of their slopes equals to the squared sample correlation.

第一节课没咋听

失拟 lack of fit,用 GLT 检验

  • 区分 full model 和 reduced model
  • 三个模型,最细的是 4,1、3 次一级,2 最粗
  • 跟上一级比,线性是不是足够
  • 以前是检验是不是线性,往下比
  • SSE=SSPE+SSLF, pure error, lack of fit, 必须有重复

补救

  • power transformation
  • 可用 MLE 估计 λ\lambda.
    • pdf 的 transformation
    • 不硬碰硬优化 likelihood function,做变换搞成 LS 之形式解之
  • 关注 λ\lambda 的置信区间
    • 找一个好算的
    • 可解释性
    • 1 在不在区间里,很重要(不做变换)

Regression through the origin (过原点回归)

  • 很多东西会崩溃,比如 Cov(b,Yˉ)\mathrm{Cov}(b,\bar{Y}) 将不再为零

反向预测

  • X^h=Yh−b0b1\hat{X}_{h}=\frac{Y_{h}-b_{0}}{b_{1}}.
  • 校准
  • 为啥不 X∼YX\sim Y?意义不同
  • 两条回归线的夹角越小,相关系数越大

R2R^{2}:

  • 啥也不代表,拟合程度、预测能力
  • 不能用比较 R2R^{2} 来评价模型
  • 没有因果理解
  • Adjusted R2 一样的

6 Remedies and Miscellaneous Topics
https://wtx17.github.io/2026/10/27/Lec-6-Remedies-and-Miscellaneous-Topics/
作者
wtx
发布于
2026年10月27日
更新于
2026年11月6日
许可协议