| \(i\) | \(y_i\) | \(\hat y_i\) | \(e_i\) | \(h_{ii}\) | \(d_i\) | \(r_i\) | \(t_i\) | \(e_{(i)}\) |
|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 2.804 | -0.804 | 0.394 | -0.478 | -0.615 | -0.592 | -1.328 |
| 2 | 3 | 3.686 | -0.686 | 0.191 | -0.408 | -0.454 | -0.433 | -0.848 |
| 3 | 2 | 2.401 | -0.401 | 0.375 | -0.238 | -0.301 | -0.286 | -0.641 |
| 4 | 7 | 4.972 | 2.028 | 0.174 | 1.206 | 1.327 | 1.394 | 2.454 |
| 5 | 6 | 5.853 | 0.147 | 0.159 | 0.087 | 0.095 | 0.090 | 0.174 |
| 6 | 8 | 7.139 | 0.861 | 0.085 | 0.512 | 0.535 | 0.513 | 0.941 |
| 7 | 10 | 8.424 | 1.576 | 0.178 | 0.937 | 1.033 | 1.038 | 1.917 |
| 8 | 7 | 10.591 | -3.591 | 0.166 | -2.135 | -2.338 | -3.517 | -4.304 |
| 9 | 8 | 9.306 | -1.306 | 0.129 | -0.777 | -0.832 | -0.817 | -1.500 |
| 10 | 12 | 11.877 | 0.123 | 0.369 | 0.073 | 0.092 | 0.087 | 0.195 |
| 11 | 11 | 10.188 | 0.812 | 0.494 | 0.483 | 0.679 | 0.657 | 1.604 |
| 12 | 14 | 12.759 | 1.241 | 0.285 | 0.738 | 0.873 | 0.860 | 1.737 |
8 Residual Analysis and Model Adequacy Checking
The tests and intervals of Chapter 7 are valid only if the assumptions of Section 1.5 hold: the model has the correct form, the errors have zero mean, constant variance, are uncorrelated and normally distributed. Gross violations can make the fitted model unstable, so that a different sample gives a totally different model with opposite conclusions. Summary statistics such as \(R^2\), \(t\) and \(F\) are global properties of the model and cannot reveal such violations. The principal tool for checking assumptions is the set of residuals \(e_i=y_i-\hat y_i\), which are the observable counterparts of the errors (Montgomery, Peck, and Vining 2021; Draper and Smith 1998; Chatterjee and Hadi 2012).
8.1 Properties of residuals
From Section 4.4, \(\mathbf e=(\mathbf I-\mathbf H)\mathbf y=(\mathbf I-\mathbf H)\boldsymbol\varepsilon\), so
\[E(\mathbf e)=\mathbf 0,\qquad V(\mathbf e)=\sigma^2(\mathbf I-\mathbf H),\qquad V(e_i)=\sigma^2(1-h_{ii}),\qquad Cov(e_i,e_j)=-\sigma^2h_{ij}.\]
The residuals have mean zero, but unlike the errors they are correlated and have unequal variances. Residuals at points remote in \(x\)-space (large \(h_{ii}\)) have small variance: the fitted surface is pulled towards such points. The residuals also satisfy \(p\) linear constraints (\(\mathbf X'\mathbf e=\mathbf 0\)), so only \(n-p\) of them are free. Their average variance is
\[\frac1n\sum_{i=1}^nV(e_i)=\frac{\sigma^2}n\operatorname{tr}(\mathbf I-\mathbf H)=\frac{n-p}n\sigma^2,\]
which is estimated by \(SS_{Res}/n\); for this reason \(MS_{Res}\) is the natural scale for residuals.
8.2 Methods for scaling residuals
Raw residuals are in the units of \(y\), so their size is hard to judge. Several scaled versions are used.
8.2.1 Standardized residuals
\[d_i=\frac{e_i}{\sqrt{MS_{Res}}},\qquad i=1,2,\ldots,n. \tag{8.1}\]
The standardized residuals have mean zero, \(E(d_i)=0\), and approximately unit variance, \(V(d_i)\approx1\). A large standardized residual, \(|d_i|>3\), potentially indicates an outlier.
8.2.2 Studentized residuals
Since \(V(e_i)=\sigma^2(1-h_{ii})\), a better scaling divides each residual by its own estimated standard deviation:
\[r_i=\frac{e_i}{\sqrt{MS_{Res}(1-h_{ii})}},\qquad i=1,2,\ldots,n. \tag{8.2}\]
The studentized residuals have \(E(r_i)=0\) and \(V(r_i)=1\) (exactly constant variance when \(\sigma^2\) is known), regardless of the location of \(\mathbf x_i\). If there is only one explanatory variable, \(h_{ii}=\frac1n+\frac{(x_i-\bar x)^2}{S_{xx}}\) and
\[r_i=\frac{e_i}{\sqrt{MS_{Res}\left[1-\left(\frac1n+\frac{(x_i-\bar x)^2}{S_{xx}}\right)\right]}},\qquad i=1,2,\ldots,n. \tag{8.3}\]
In big data sets \(h_{ii}\) is small for most points, so \(r_i\) and \(d_i\) do not differ much. They differ most for points remote from the centre of the data, which is exactly where a raw residual is misleadingly small. (R calls \(r_i\) the standardized residual: rstandard().)
8.2.3 PRESS residuals
Consider deleting the \(i\)th observation, fitting the regression to the remaining \(n-1\) observations, and predicting \(y_i\) from that fit:
- Delete the \(i\)th observation \((y_i,\mathbf x_i')\).
- Fit the regression to the remaining \((n-1)\) observations.
- Calculate the predicted value \(\hat y_{(i)}\) of \(y_i\) corresponding to the deleted observation.
- Compute the prediction error \(e_{(i)}=y_i-\hat y_{(i)}\).
- Calculate \(e_{(i)}\) for all \(i=1,2,\ldots,n\) in a similar way.
Here \(\hat y_{(i)}\) is the fitted value of the \(i\)th response based on all observations except the \(i\)th one. The prediction errors \(e_{(i)}=y_i-\hat y_{(i)}\) are called PRESS residuals, because they are used in computing the prediction error sum of squares (Allen 1974). They are also called deleted residuals.
At first sight \(n\) separate regressions are needed. Fortunately there is a simple relation between \(e_i\) and \(e_{(i)}\):
\[\boxed{e_{(i)}=\frac{e_i}{1-h_{ii}}} \tag{8.4}\]
The proof uses the following result on the inverse of a matrix after deleting one row of \(\mathbf X\).
Let \(\mathbf X'\mathbf X\) be a \(p\times p\) matrix and let \(\mathbf x_i'\) be the \(i\)th row vector that is removed from \(\mathbf X\). Then (Sherman and Morrison 1950)
\[\left[\mathbf X'\mathbf X-\mathbf x_i\mathbf x_i'\right]^{-1}=(\mathbf X'\mathbf X)^{-1}+\frac{(\mathbf X'\mathbf X)^{-1}\mathbf x_i\mathbf x_i'(\mathbf X'\mathbf X)^{-1}}{1-\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf x_i}.\]
Proof of Equation 8.4. Let \(\mathbf X_{(i)}\) be the \(\mathbf X\) matrix without the \(i\)th row vector \(\mathbf x_i'\) and \(\mathbf y_{(i)}\) the response vector without \(y_i\). Then \(\mathbf X_{(i)}'\mathbf X_{(i)}=\mathbf X'\mathbf X-\mathbf x_i\mathbf x_i'\) and, using the result with \(h_{ii}=\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf x_i\),
\[\left[\mathbf X_{(i)}'\mathbf X_{(i)}\right]^{-1}=(\mathbf X'\mathbf X)^{-1}+\frac{(\mathbf X'\mathbf X)^{-1}\mathbf x_i\mathbf x_i'(\mathbf X'\mathbf X)^{-1}}{1-h_{ii}}.\]
The estimate without the \(i\)th observation is \(\hat{\boldsymbol\beta}_{(i)}=\left(\mathbf X_{(i)}'\mathbf X_{(i)}\right)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}\), and
\[\begin{aligned} e_{(i)}&=y_i-\hat y_{(i)}=y_i-\mathbf x_i'\hat{\boldsymbol\beta}_{(i)}=y_i-\mathbf x_i'\left(\mathbf X_{(i)}'\mathbf X_{(i)}\right)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}\\ &=y_i-\mathbf x_i'\left[(\mathbf X'\mathbf X)^{-1}+\frac{(\mathbf X'\mathbf X)^{-1}\mathbf x_i\mathbf x_i'(\mathbf X'\mathbf X)^{-1}}{1-h_{ii}}\right]\mathbf X_{(i)}'\mathbf y_{(i)}\\ &=y_i-\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}-\frac{h_{ii}\,\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}}{1-h_{ii}}\\ &=\frac{(1-h_{ii})y_i-(1-h_{ii})\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}-h_{ii}\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}}{1-h_{ii}}\\ &=\frac{(1-h_{ii})y_i-\mathbf x_i'(\mathbf X'\mathbf X)^{-1}\mathbf X_{(i)}'\mathbf y_{(i)}}{1-h_{ii}}. \end{aligned}\]
Now use \(\mathbf X'\mathbf y=\mathbf X_{(i)}'\mathbf y_{(i)}+\mathbf x_iy_i\), i.e. \(\mathbf X_{(i)}'\mathbf y_{(i)}=\mathbf X'\mathbf y-\mathbf x_iy_i\):
\[\begin{aligned} e_{(i)}&=\frac{(1-h_{ii})y_i-\mathbf x_i'(\mathbf X'\mathbf X)^{-1}(\mathbf X'\mathbf y-\mathbf x_iy_i)}{1-h_{ii}}=\frac{(1-h_{ii})y_i-\mathbf x_i'\hat{\boldsymbol\beta}+h_{ii}y_i}{1-h_{ii}}\\ &=\frac{y_i-\hat y_i}{1-h_{ii}}=\frac{e_i}{1-h_{ii}}.\qquad\blacksquare \end{aligned}\]
Interpretation
- Large PRESS residuals identify highly influential points.
- A large difference between \(e_i\) and \(e_{(i)}\) indicates a point where the model fits the data well but a model built without that point predicts poorly: the point is pulling the fit towards itself (it has a large \(h_{ii}\)).
Standardized PRESS residual
Since \(V(e_{(i)})=V(e_i)/(1-h_{ii})^2=\sigma^2/(1-h_{ii})\),
\[\frac{e_{(i)}}{\sqrt{V(e_{(i)})}}=\frac{e_i/(1-h_{ii})}{\sqrt{\sigma^2/(1-h_{ii})}}=\frac{e_i}{\sqrt{\sigma^2(1-h_{ii})}},\]
which, with \(\sigma^2\) estimated by \(MS_{Res}\), is the same as the studentized residual Equation 8.2.
The PRESS statistic and prediction \(R^2\)
\[PRESS=\sum_{i=1}^ne_{(i)}^2=\sum_{i=1}^n\left(\frac{e_i}{1-h_{ii}}\right)^2,\qquad R^2_{\text{prediction}}=1-\frac{PRESS}{SS_T}. \tag{8.5}\]
PRESS measures how well the model predicts new observations (it is leave-one-out cross-validation) and is used to compare models (Chapter 15).
8.2.4 R-student (externally studentized residual)
In Equation 8.2 the estimate \(MS_{Res}\) uses all observations, including the \(i\)th. If the \(i\)th point is an outlier it inflates \(MS_{Res}\) and masks itself. Using instead the estimate of \(\sigma^2\) obtained without the \(i\)th observation,
\[S_{(i)}^2=\frac{(n-p)MS_{Res}-e_i^2/(1-h_{ii})}{n-p-1}, \tag{8.6}\]
gives the R-student (externally studentized) residual
\[t_i=\frac{e_i}{\sqrt{S_{(i)}^2(1-h_{ii})}},\qquad i=1,2,\ldots,n. \tag{8.7}\]
Under the model, \(t_i\sim t_{n-p-1}\) exactly, which provides a formal test for a single outlier. Because \(n\) such tests are made, the Bonferroni critical value \(t_{\alpha/(2n),\,n-p-1}\) is used.
Example 8.1 Compute the scaled residuals and PRESS for the illustrative model of Example 4.1.
Solution
With \(MS_{Res}=2.829\), the standardized, studentized and R-student residuals and PRESS residuals are given in Table 8.1. For observation 8, the largest residual \(e=-3.591\) has \(h=0.166\), so \(r=-3.591/\sqrt{2.829(1-0.166)}=-2.338\) and the PRESS residual is \(-3.591/(1-0.166)=-4.304\). No \(|t_i|\) exceeds the Bonferroni critical value \(t_{0.05/24,\,8}=3.962\), so there is no outlier.
\(PRESS=\sum e_{(i)}^2=39.918\), compared with \(SS_{Res}=25.459\), and \(R^2_{\text{prediction}}=1-39.918/165.000=0.758\): the model is expected to explain about 76% of the variability in predicting new observations, against \(R^2=0.846\) for the data used to fit it.
8.3 Residual plots
Graphical analysis of residuals is the most effective way to investigate model adequacy.
- Normal probability (Q–Q) plot of \(r_i\) or \(t_i\): points should lie near a straight line. A curve that bends up at both ends indicates heavy tails; an S-shape indicates light tails; a curve at one end indicates skewness; isolated points far off the line are outliers.
- Residuals versus fitted values \(\hat y_i\): should be a horizontal band around zero. A funnel (spread increasing with \(\hat y\)) indicates non-constant variance; a curve indicates a missing quadratic term or a wrong functional form.
- Residuals versus each regressor \(x_j\): patterns indicate that \(x_j\) should enter the model non-linearly (for example \(x_j^2\) or \(\log x_j\)).
- Residuals versus regressors not in the model: a pattern indicates that the omitted variable should be included.
- Residuals in time (or field) order: runs of positive and negative residuals indicate autocorrelation (Chapter 10) or spatial trend in the field.
- Partial residual (component-plus-residual) plots, \(e_i+\hat\beta_jx_{ij}\) against \(x_{ij}\), and added variable plots (Chapter 7): show the form of the partial relation with \(x_j\).
The diagnostic plots of the paddy model (Figure 8.1) single out farm 17: it has the largest negative residual, deviates from the normal line, and lies at the edge of the leverage plot. It is investigated in Chapter 9.
8.4 Testing normality of errors
Formal tests supplement the normal probability plot.
- Shapiro–Wilk test (Shapiro and Wilk 1965): \(W=\left(\sum a_ie_{(i)}\right)^2/\sum(e_i-\bar e)^2\), where \(e_{(i)}\) are the ordered residuals and \(a_i\) are constants from the expected values of normal order statistics. Small \(W\) indicates non-normality. It is the most powerful of the common tests for small and moderate \(n\).
- Kolmogorov–Smirnov (Lilliefors) and Anderson–Darling tests compare the empirical distribution of the standardized residuals with the normal distribution.
- Jarque–Bera test (common in econometrics): \(JB=\frac n6\left[S^2+\frac{(K-3)^2}4\right]\sim\chi^2_2\), where \(S\) and \(K\) are the skewness and kurtosis of the residuals.
For the paddy model, the Shapiro–Wilk test on the studentized residuals gives \(W=0.9747\) with \(p=0.6741\).
Moderate departures from normality matter little for estimation and, by the central limit theorem, little for tests in large samples. Heavy tails and outliers matter more, because least squares gives them too much weight; robust methods (Chapter 16) are then preferable. A non-significant normality test in a small sample does not prove normality.
8.5 Testing homoscedasticity
- Breusch–Pagan test (Breusch and Pagan 1979): regress the squared residuals \(e_i^2\) (scaled by \(SS_{Res}/n\)) on the regressors (or on any variables suspected to drive the variance). Under \(H_0\) of constant variance, \(\tfrac12SS_R\) of this auxiliary regression (or \(nR^2_{aux}\) in the studentized version of Koenker) is approximately \(\chi^2_k\).
- White’s test: as Breusch–Pagan, but the auxiliary regression includes the regressors, their squares and cross products.
- Goldfeld–Quandt test (Goldfeld and Quandt 1965): order the observations by the variable suspected to be related to the variance, omit \(c\) central observations, fit separate regressions to the first and last \((n-c)/2\) observations, and compare \(F=SS_{Res,2}/SS_{Res,1}\) with \(F_{(n-c-2p)/2,\,(n-c-2p)/2}\).
- Bartlett’s or Levene’s test: when there are groups of observations (for example replicates at each \(x\)), compare the within-group variances.
For the paddy model, the Breusch–Pagan statistic is \(4.028\) on 3 df (\(p=0.2585\)), so constant variance is not rejected. Remedies for non-constant variance are discussed in Chapter 12.
8.6 Lack of fit and pure error
The residual sum of squares contains two kinds of variation: random error, and any systematic departure of the true mean function from the fitted model (lack of fit). When there are replicate observations (several \(y\) values at the same \(x\)), the two can be separated, giving a formal test of the adequacy of the model’s form.
Suppose there are \(m\) distinct levels \(x_1,\ldots,x_m\), with \(n_i\) observations \(y_{ij}\) at level \(x_i\), \(n=\sum n_i\). Then
\[\underbrace{\sum_i\sum_j(y_{ij}-\hat y_i)^2}_{SS_{Res}}=\underbrace{\sum_i\sum_j(y_{ij}-\bar y_i)^2}_{SS_{PE}}+\underbrace{\sum_in_i(\bar y_i-\hat y_i)^2}_{SS_{LOF}}. \tag{8.8}\]
The pure error sum of squares \(SS_{PE}\), with \(n-m\) df, depends only on the variation among replicates and estimates \(\sigma^2\) whatever the true mean function. The lack of fit sum of squares \(SS_{LOF}\), with \(m-p\) df, measures how far the fitted values are from the level means. The test of \(H_0\): the model form is adequate is
\[F_0=\frac{SS_{LOF}/(m-p)}{SS_{PE}/(n-m)}=\frac{MS_{LOF}}{MS_{PE}}\sim F_{m-p,\,n-m}. \tag{8.9}\]
If \(F_0\) is significant, the model is inadequate and a different form should be tried. If not, \(MS_{LOF}\) and \(MS_{PE}\) may be pooled to estimate \(\sigma^2\).
Example 8.2 A replicated nitrogen trial with six doses (0 to 200 kg N/ha) and three replicates per dose (csv/ndose.csv) was analysed by fitting a straight line. Test for lack of fit.
Solution
The straight line gives \(SS_{Res}=2.8516\) on 16 df. The pure error sum of squares, the variation of the replicates about their dose means, is \(SS_{PE}=0.1927\) on \(18-6=12\) df, so \(SS_{LOF}=2.8516-0.1927=2.6588\) on \(6-2=4\) df.
| Source | SS | df | MS | \(F\) |
|---|---|---|---|---|
| Regression | 15.7112 | 1 | ||
| Residual | 2.8516 | 16 | ||
| Lack of fit | 2.6588 | 4 | 0.6647 | 41.39 |
| Pure error | 0.1927 | 12 | 0.0161 | |
| Total | 18.5628 | 17 |
\(F_0=41.39\) far exceeds \(F_{0.05}(4,12)=3.26\): the straight line is inadequate, even though its \(R^2=0.846\) looks respectable. The yield response to N is curved (diminishing returns), and a quadratic model is fitted in Chapter 13.
When there are no exact replicates, near neighbours (observations with nearly the same \(\mathbf x\)) can be grouped to give an approximate pure error estimate. In designed experiments the replicates of each treatment provide pure error naturally, which is one reason replication is a basic principle of experimental design.
8.7 R practical
pd <- read.csv("csv/paddy.csv")
fit <- lm(yield ~ N + P + K, data = pd)
e <- resid(fit) # raw residuals
d <- e / sigma(fit) # standardized d_i
r <- rstandard(fit) # studentized r_i (internal)
t <- rstudent(fit) # R-student t_i (external)
h <- hatvalues(fit)
pe <- e / (1 - h) # PRESS residuals
PRESS <- sum(pe^2)
c(PRESS = PRESS, R2pred = 1 - PRESS / sum((pd$yield - mean(pd$yield))^2))#> PRESS R2pred
#> 241.9882371 0.1551683
round(head(cbind(e, d, r, t, h, pe)), 3)#> e d r t h pe
#> 1 1.599 0.672 0.721 0.714 0.131 1.840
#> 2 5.433 2.285 2.457 2.749 0.135 6.282
#> 3 0.217 0.091 0.095 0.093 0.076 0.234
#> 4 0.502 0.211 0.227 0.222 0.132 0.579
#> 5 -2.261 -0.951 -0.978 -0.977 0.055 -2.392
#> 6 -2.512 -1.056 -1.161 -1.169 0.173 -3.036
shapiro.test(r) # normality#>
#> Shapiro-Wilk normality test
#>
#> data: r
#> W = 0.97471, p-value = 0.6741
lmtest::bptest(fit) # Breusch-Pagan (studentized)#>
#> studentized Breusch-Pagan test
#>
#> data: fit
#> BP = 4.0276, df = 3, p-value = 0.2585
lmtest::gqtest(fit, order.by = ~ N, data = pd) # Goldfeld-Quandt#>
#> Goldfeld-Quandt test
#>
#> data: fit
#> GQ = 1.9822, df1 = 11, df2 = 11, p-value = 0.1359
#> alternative hypothesis: variance increases from segment 1 to 2
car::outlierTest(fit) # Bonferroni test on max |t_i|#> No Studentized residuals with Bonferroni p < 0.05
#> Largest |rstudent|:
#> rstudent unadjusted p-value Bonferroni p
#> 17 -3.034943 0.0055511 0.16653
car::crPlots(fit) # component + residual plots
# Lack of fit test with replicated data
nd <- read.csv("csv/ndose.csv")
line <- lm(yield ~ N, data = nd)
sat <- lm(yield ~ factor(N), data = nd) # one mean per dose = pure error model
anova(line, sat) # F for lack of fit#> Analysis of Variance Table
#>
#> Model 1: yield ~ N
#> Model 2: yield ~ factor(N)
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 16 2.85157
#> 2 12 0.19273 4 2.6588 41.386 6.287e-07 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Looking at residuals
Before electronic computers, residuals were rarely examined because each one required extra hand calculation. The systematic study of residuals began with F. J. Anscombe and J. W. Tukey in the early 1960s, who argued that “the residuals are the part of the data that the model has not explained, and must be examined”. Anscombe’s famous quartet (1973), four data sets with identical regression lines, correlations and \(R^2\) but completely different scatter plots, remains the most persuasive argument that summary statistics alone can never establish the adequacy of a regression model. D. M. Allen’s PRESS statistic (1974) brought cross-validation into routine regression practice (Allen 1974).
“The greatest value of a picture is when it forces us to notice what we never expected to see.”
- John W. Tukey
8.8 Practical exercises
8.8.1 Practical 8.1: Scaled residuals and PRESS for the cassava data
For the cassava potassium data of Practical 3.1, compute for every observation the leverage \(h_{ii}\), the standardized, studentized and R-student residuals and the PRESS residuals. Compute PRESS and \(R^2_{\text{prediction}}\).
Solution
\(MS_{Res}=0.13943\). For simple regression \(h_{ii}=\frac16+\frac{(x_i-62.5)^2}{10937.5}\). Using Equation 8.1, Equation 8.2, Equation 8.7 and Equation 8.4:
| \(x\) | \(e_i\) | \(h_{ii}\) | \(d_i\) | \(r_i\) | \(t_i\) | \(e_{(i)}\) |
|---|---|---|---|---|---|---|
| 0 | -0.1286 | 0.5238 | -0.344 | -0.499 | -0.446 | -0.2700 |
| 25 | -0.1971 | 0.2952 | -0.528 | -0.629 | -0.574 | -0.2797 |
| 50 | 0.5343 | 0.1810 | 1.431 | 1.581 | 2.236 | 0.6523 |
| 75 | -0.2343 | 0.1810 | -0.627 | -0.693 | -0.640 | -0.2860 |
| 100 | 0.2971 | 0.2952 | 0.796 | 0.948 | 0.932 | 0.4216 |
| 125 | -0.2714 | 0.5238 | -0.727 | -1.053 | -1.073 | -0.5700 |
\(PRESS=1.1612\) against \(SS_{Res}=0.5577\), and \(R^2_{\text{prediction}}=1-1.1612/68.3750=0.9830\). The end points (\(x=0\) and \(x=125\)) have the largest leverage (0.524), so their PRESS residuals are inflated most relative to \(e_i\). No \(|t_i|\) exceeds the Bonferroni value \(t_{0.05/12,3}=6.23\).
Doing it in R
cassava <- data.frame(K = c(0, 25, 50, 75, 100, 125),
yield = c(18.2, 20.1, 22.8, 24.0, 26.5, 27.9))
fk <- lm(yield ~ K, data = cassava)
hk <- hatvalues(fk); ek <- resid(fk)
round(data.frame(e = ek, h = hk, d = ek / sigma(fk), r = rstandard(fk),
t = rstudent(fk), press = ek / (1 - hk)), 4)#> e h d r t press
#> 1 -0.1286 0.5238 -0.3443 -0.4990 -0.4462 -0.2700
#> 2 -0.1971 0.2952 -0.5280 -0.6289 -0.5738 -0.2797
#> 3 0.5343 0.1810 1.4309 1.5810 2.2357 0.6523
#> 4 -0.2343 0.1810 -0.6274 -0.6933 -0.6401 -0.2860
#> 5 0.2971 0.2952 0.7958 0.9479 0.9323 0.4216
#> 6 -0.2714 0.5238 -0.7269 -1.0534 -1.0732 -0.5700
PRESSk <- sum((ek / (1 - hk))^2)
c(PRESS = PRESSk, R2pred = 1 - PRESSk / sum((cassava$yield - mean(cassava$yield))^2))#> PRESS R2pred
#> 1.1611648 0.9830177
8.8.2 Practical 8.2: Lack of fit with replicated doses
Fodder yield (t/ha) of hybrid napier at four nitrogen levels, each replicated twice, is given below. Fit a straight line and test for lack of fit.
| N (kg/ha) | 50 | 50 | 100 | 100 | 150 | 150 | 200 | 200 |
|---|---|---|---|---|---|---|---|---|
| Yield | 42 | 45 | 58 | 61 | 66 | 68 | 69 | 70 |
Solution
The straight line gives \(SS_{Res}=103.8500\) on 6 df. Pure error from the replicates is \(SS_{PE}=\sum\sum(y_{ij}-\bar y_i)^2=11.50\) on \(8-4=4\) df, so \(SS_{LOF}=92.3500\) on \(4-2=2\) df. By Equation 8.9,
\[F_0=\frac{92.3500/2}{11.50/4}=16.06,\]
compared with \(F_{0.05}(2,4)=6.94\). The straight line shows significant lack of fit: the response is curved, and a quadratic should be tried.
Doing it in R
napier <- data.frame(N = rep(c(50, 100, 150, 200), each = 2),
y = c(42, 45, 58, 61, 66, 68, 69, 70))
line <- lm(y ~ N, data = napier)
pure <- lm(y ~ factor(N), data = napier)
anova(line, pure) # lack-of-fit F test#> Analysis of Variance Table
#>
#> Model 1: y ~ N
#> Model 2: y ~ factor(N)
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 6 103.85
#> 2 4 11.50 2 92.35 16.061 0.01226 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(lm(y ~ N + I(N^2), data = napier), pure) # does a quadratic fit?#> Analysis of Variance Table
#>
#> Model 1: y ~ N + I(N^2)
#> Model 2: y ~ factor(N)
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 5 12.725
#> 2 4 11.500 1 1.225 0.4261 0.5495
8.9 Chapter Summary
Fill in the blanks
Answers are given at the end of the chapter.
The variance of the \(i\)th residual is __________.
The standardized residual is \(d_i=\) __________.
A standardized residual with \(|d_i|>\) __________ potentially indicates an outlier.
The studentized residual divides \(e_i\) by __________.
The PRESS residual is related to the ordinary residual by \(e_{(i)}=\) __________.
The standardized PRESS residual is the same as the __________ residual.
Under the model, the R-student residual follows a \(t\) distribution with __________ degrees of freedom.
A funnel shape in the plot of residuals against fitted values indicates __________.
The pure error sum of squares has __________ degrees of freedom when there are \(m\) distinct levels and \(n\) observations.
The lack of fit sum of squares has __________ degrees of freedom.
Short-answer questions
Why do residuals not have equal variances even when the errors do?
Describe the methods for scaling residuals.
Explain the procedure for computing PRESS residuals.
State the Sherman–Morrison result and use it to prove \(e_{(i)}=e_i/(1-h_{ii})\).
Show that the standardized PRESS residual equals the studentized residual.
Why is R-student preferred to the studentized residual for detecting outliers?
What does a large difference between \(e_i\) and \(e_{(i)}\) indicate?
Describe the residual plots used to check model adequacy and what each reveals.
Describe the Breusch–Pagan and Goldfeld–Quandt tests.
Explain lack of fit and pure error. When can the lack of fit test be performed?
Numerical and conceptual questions
Answers are given at the end of the chapter.
\(e_i=2.4\), \(MS_{Res}=1.44\), \(h_{ii}=0.36\). Compute \(d_i\), \(r_i\) and \(e_{(i)}\).
For Question 1 with \(n=20\), \(p=4\), compute \(S^2_{(i)}\) and \(t_i\).
A model gives \(SS_{Res}=40\), \(PRESS=65\), \(SS_T=200\). Find \(R^2\) and \(R^2_{\text{prediction}}\).
In simple regression with \(n=10\), \(\bar x=5\), \(S_{xx}=40\), find \(h_{ii}\) for \(x_i=9\).
A data set has \(n=24\) observations at 8 distinct \(x\) levels; a straight line is fitted. Give the df for pure error and lack of fit.
For Question 5, \(SS_{Res}=30\) and \(SS_{PE}=18\). Test for lack of fit.
If \(h_{ii}=1\), what happens to \(e_i\) and \(e_{(i)}\)?
Two observations have the same \(e_i=1.5\), with \(h_{ii}=0.1\) and \(0.6\). Which has the larger studentized residual?
Important formulae
Scaled residuals:
\[ d_i=\frac{e_i}{\sqrt{MS_{Res}}},\qquad r_i=\frac{e_i}{\sqrt{MS_{Res}(1-h_{ii})}},\qquad t_i=\frac{e_i}{\sqrt{S^2_{(i)}(1-h_{ii})}} \]
Deleted variance estimate:
\[ S^2_{(i)}=\frac{(n-p)MS_{Res}-e_i^2/(1-h_{ii})}{n-p-1} \]
PRESS residual and statistic:
\[ e_{(i)}=\frac{e_i}{1-h_{ii}},\qquad PRESS=\sum\left(\frac{e_i}{1-h_{ii}}\right)^2,\qquad R^2_{pred}=1-\frac{PRESS}{SS_T} \]
Lack of fit test:
\[ F_0=\frac{SS_{LOF}/(m-p)}{SS_{PE}/(n-m)} \]
Quick revision
- \(V(e_i)=\sigma^2(1-h_{ii})\) → residuals are correlated with unequal variances.
- \(d_i\) → divide by \(\sqrt{MS_{Res}}\); \(r_i\) → also by \(\sqrt{1-h_{ii}}\); \(t_i\) → use \(S_{(i)}\).
- PRESS residual \(=e_i/(1-h_{ii})\) → leave-one-out prediction error without refitting.
- Plots: Q–Q (normality), residual vs fitted (variance, form), vs \(x_j\) (form), vs order (autocorrelation).
- Tests: Shapiro–Wilk (normality), Breusch–Pagan, Goldfeld–Quandt (constant variance).
- Replicates → \(SS_{Res}=SS_{PE}+SS_{LOF}\) → \(F\) test of model form.
Answers to fill in the blanks
1. \(\sigma^2(1-h_{ii})\) 2. \(e_i/\sqrt{MS_{Res}}\) 3. 3 4. \(\sqrt{MS_{Res}(1-h_{ii})}\) 5. \(e_i/(1-h_{ii})\) 6. Studentized 7. \(n-p-1\) 8. Non-constant variance (heteroscedasticity) 9. \(n-m\) 10. \(m-p\)
Solutions to numerical and conceptual questions
\(d_i=2.4/1.2=2.0\); \(r_i=2.4/\sqrt{1.44\times0.64}=2.5\); \(e_{(i)}=2.4/0.64=3.75\) (Equation 8.1, Equation 8.2, Equation 8.4).
By Equation 8.6, \(S^2_{(i)}=\dfrac{16(1.44)-5.76/0.64}{15}=\dfrac{23.04-9}{15}=0.936\); \(t_i=2.4/\sqrt{0.936\times0.64}=3.10\).
\(R^2=1-40/200=0.80\); \(R^2_{pred}=1-65/200=0.675\).
\(h_{ii}=\frac1{10}+\frac{(9-5)^2}{40}=0.5\).
Pure error: \(24-8=16\) df; lack of fit: \(8-2=6\) df.
\(SS_{LOF}=12\); by Equation 8.9, \(F_0=\dfrac{12/6}{18/16}=1.78<F_{0.05}(6,16)=2.74\); no significant lack of fit.
\(V(e_i)=0\), so \(e_i=0\): the fit passes exactly through the point, and \(e_{(i)}\) is undefined; the point alone determines one parameter.
The one with \(h_{ii}=0.6\): \(r_i\propto1/\sqrt{1-h_{ii}}\), giving \(1.5/\sqrt{0.4}=2.37\) vs \(1.5/\sqrt{0.9}=1.58\) (in units of \(\sqrt{MS_{Res}}\)).