7 Hypothesis Testing, Confidence Regions and Goodness of Fit
Once a model has been fitted, we want to know whether it explains a significant part of the variation in the response, which regressors contribute, how precisely each coefficient is estimated, and how well the model fits overall. This chapter develops the analysis of variance for regression, \(t\) tests and confidence intervals for individual coefficients, joint confidence regions, the coefficient of determination and its adjusted form, tests of general linear hypotheses (sub-hypotheses) and restricted least squares (Draper and Smith 1998; Montgomery, Peck, and Vining 2021; Kutner, Nachtsheim, and Neter 2004). Throughout, the errors are assumed to be \(N(\mathbf 0,\sigma^2\mathbf I)\).
7.1 Distribution of \(\hat{\boldsymbol\beta}\) and independence from \(\hat\sigma^2\)
Since \(\mathbf y\sim N(\mathbf X\boldsymbol\beta,\sigma^2\mathbf I)\) and \(\hat{\boldsymbol\beta}=(\mathbf X'\mathbf X)^{-1}\mathbf X'\mathbf y\) is a linear function of \(\mathbf y\),
\[\hat{\boldsymbol\beta}\sim N_p\left(\boldsymbol\beta,\ \sigma^2(\mathbf X'\mathbf X)^{-1}\right),\qquad \hat\beta_j\sim N(\beta_j,\ \sigma^2C_{jj}), \tag{7.1}\]
where \(C_{jj}\) is the \(j\)th diagonal element of \((\mathbf X'\mathbf X)^{-1}\). The estimate of \(\sigma^2\) is
\[\hat\sigma^2=\frac{SS_{Res}}{n-p}=\frac{(\mathbf y-\hat{\mathbf y})'(\mathbf y-\hat{\mathbf y})}{n-p}=\frac{\mathbf y'\left[\mathbf I-\mathbf X(\mathbf X'\mathbf X)^{-1}\mathbf X'\right]\mathbf y}{n-p}=\frac{\mathbf y'\bar{\mathbf H}\mathbf y}{n-p}.\]
\(\hat{\boldsymbol\beta}\) and \(\hat\sigma^2\) are independent
\[Cov\left(\hat{\boldsymbol\beta},\ \mathbf e\right)=Cov\left((\mathbf X'\mathbf X)^{-1}\mathbf X'\mathbf y,\ (\mathbf I-\mathbf H)\mathbf y\right)=\sigma^2(\mathbf X'\mathbf X)^{-1}\mathbf X'(\mathbf I-\mathbf H)=\mathbf 0,\]
since \(\mathbf X'(\mathbf I-\mathbf H)=\mathbf 0\) (equivalently \((\mathbf X'\mathbf X)^{-1}\mathbf X'\bar{\mathbf H}=\mathbf 0\)). Under normality, zero covariance between jointly normal vectors implies independence, so \(\hat{\boldsymbol\beta}\) is independent of \(\mathbf e\) and hence of \(\hat\sigma^2=\mathbf e'\mathbf e/(n-p)\). Together with \((n-p)\hat\sigma^2/\sigma^2\sim\chi^2_{n-p}\) (Equation 4.14), this independence is what makes the \(t\) and \(F\) statistics below exact.
The residual sum of squares can be written in several equivalent ways:
\[SS_{Res}=\mathbf e'\mathbf e=\mathbf y'(\mathbf I-\mathbf H)'(\mathbf I-\mathbf H)\mathbf y=\mathbf y'(\mathbf I-\mathbf H)\mathbf y=\mathbf y'\bar{\mathbf H}\mathbf y=\mathbf y'\mathbf y-\mathbf y'\mathbf H\mathbf y.\]
7.2 Test of significance of regression (ANOVA)
The overall test asks whether there is a linear relation between \(y\) and any of the regressors:
\[H_0:\beta_1=\beta_2=\cdots=\beta_{p-1}=0\qquad\text{vs}\qquad H_1:\beta_j\neq0\ \text{for at least one }j=1,2,\ldots,p-1.\]
This is an overall, omnibus or global test of model adequacy. The intercept is not included in \(H_0\).
Partition of the total sum of squares
The uncorrected regression sum of squares is
\[\mathbf y'\mathbf H\mathbf y=\mathbf y'\mathbf X(\mathbf X'\mathbf X)^{-1}\mathbf X'\mathbf y=\hat{\boldsymbol\beta}'\mathbf X'\mathbf y,\]
and \(\mathbf y'\mathbf y=\mathbf y'\mathbf H\mathbf y+\mathbf y'(\mathbf I-\mathbf H)\mathbf y\). Subtracting the correction factor \(n\bar y^2\) (the sum of squares due to the intercept) from both sides gives the corrected partition
\[\underbrace{\mathbf y'\mathbf y-n\bar y^2}_{SS_T}=\underbrace{\hat{\boldsymbol\beta}'\mathbf X'\mathbf y-n\bar y^2}_{SS_R}+\underbrace{\mathbf y'\mathbf y-\hat{\boldsymbol\beta}'\mathbf X'\mathbf y}_{SS_{Res}}, \tag{7.2}\]
where \(SS_T=\sum(y_i-\bar y)^2\) is the total sum of squares, \(SS_R\) (also written \(SS_{reg}\)) the regression sum of squares and \(SS_{Res}\) the residual sum of squares. Thus \(SS_{Res}=SS_T-SS_R\).
| Source of variation | SS | df | MS | \(F\) |
|---|---|---|---|---|
| Regression | \(SS_R\) | \(p-1\) | \(MS_R=SS_R/(p-1)\) | \(F=MS_R/MS_{Res}\) |
| Error (residual) | \(SS_{Res}\) | \(n-p\) | \(MS_{Res}=SS_{Res}/(n-p)\) | |
| Total | \(SS_T\) | \(n-1\) |
Under \(H_0\), \(SS_R/\sigma^2\sim\chi^2_{p-1}\) independently of \(SS_{Res}/\sigma^2\sim\chi^2_{n-p}\), so
\[F=\frac{MS_R}{MS_{Res}}\sim F_{p-1,\,n-p}. \tag{7.3}\]
\(H_0\) is rejected at level \(\alpha\) if \(F>F_\alpha(p-1,n-p)\). Since \(E(MS_R)=\sigma^2+\boldsymbol\beta_1'\mathbf X_c'\mathbf X_c\boldsymbol\beta_1/(p-1)\), where \(\mathbf X_c\) is the centred regressor matrix and \(\boldsymbol\beta_1\) the slope vector, large values of \(F\) indicate that at least one slope is non-zero.
Example 7.1 Test the significance of the regression fitted in Example 4.1.
Solution
\(\hat{\boldsymbol\beta}'\mathbf X'\mathbf y=814.541\), \(n\bar y^2=12(7.5)^2=675.000\), so \(SS_R=814.541-675.000=139.541\); \(SS_T=840-675.000=165.000\); \(SS_{Res}=25.459\).
| Source | SS | df | MS | \(F\) |
|---|---|---|---|---|
| Regression | 139.541 | 2 | 69.771 | 24.66 |
| Residual | 25.459 | 9 | 2.829 | |
| Total | 165.000 | 11 |
\(F=24.66>F_{0.05}(2,9)=4.26\) (the \(p\)-value is 2.23e-04), so the regression is significant: at least one of \(x_1\), \(x_2\) is linearly related to \(y\).
7.3 Tests on individual regression coefficients
Consider the model \(y=\beta_0+\beta_1x_1+\cdots+\beta_{p-1}x_{p-1}+\varepsilon\) and the hypotheses
\[H_0:\beta_j=0\qquad\text{vs}\qquad H_1:\beta_j\neq0,\qquad j=1,2,\ldots,p-1.\]
From Equation 7.1 and the independence of \(\hat\beta_j\) and \(\hat\sigma^2\),
\[t=\frac{\hat\beta_j}{SE(\hat\beta_j)}\sim t_{n-p}\ \text{under }H_0,\qquad SE(\hat\beta_j)=\sqrt{\hat\sigma^2C_{jj}}, \tag{7.4}\]
where \(C_{jj}\) is the \(j\)th diagonal element of \((\mathbf X'\mathbf X)^{-1}\) corresponding to \(\hat\beta_j\). More generally, \(t_j=(\hat\beta_j-\beta_j)/\sqrt{\hat\sigma^2C_{jj}}\sim t_{n-p}\).
The \(t\) test of \(\beta_j\) is a partial (marginal) test: it tests the contribution of \(x_j\) given that all the other regressors are already in the model. A regressor may be non-significant in a multiple regression yet strongly related to \(y\) on its own, because its information is already supplied by correlated regressors. The test of \(H_0:\beta_j=0\) by \(t^2\) is identical to the partial \(F\) test of Section 7.7 with \(q=1\).
7.4 Confidence intervals for regression coefficients
Since \(\mathbf y\sim N(\mathbf X\boldsymbol\beta,\sigma^2\mathbf I)\), \(\hat{\boldsymbol\beta}\sim N\left(\boldsymbol\beta,\sigma^2(\mathbf X'\mathbf X)^{-1}\right)\) and \(\hat\beta_j\sim N(\beta_j,\sigma^2C_{jj})\),
\[P\left[-t_{\alpha/2,n-p}\le\frac{\hat\beta_j-\beta_j}{\sqrt{\hat\sigma^2C_{jj}}}\le t_{\alpha/2,n-p}\right]=1-\alpha\]
\[\Rightarrow\ P\left[\hat\beta_j-t_{\alpha/2,n-p}\sqrt{\hat\sigma^2C_{jj}}\le\beta_j\le\hat\beta_j+t_{\alpha/2,n-p}\sqrt{\hat\sigma^2C_{jj}}\right]=1-\alpha.\]
The \(100(1-\alpha)\%\) confidence interval for \(\beta_j\) is
\[\left(\hat\beta_j-t_{\alpha/2,n-p}\sqrt{\hat\sigma^2C_{jj}},\ \ \hat\beta_j+t_{\alpha/2,n-p}\sqrt{\hat\sigma^2C_{jj}}\right). \tag{7.5}\]
7.4.1 Confidence interval for the mean response and prediction interval
At a point \(\mathbf x_0=(1,x_{01},\ldots,x_{0,p-1})'\), \(\hat y_0=\mathbf x_0'\hat{\boldsymbol\beta}\) has variance \(\sigma^2\mathbf x_0'(\mathbf X'\mathbf X)^{-1}\mathbf x_0\). Hence
\[\begin{aligned} E(y\mid\mathbf x_0)&:\ \hat y_0\pm t_{\alpha/2,n-p}\sqrt{\hat\sigma^2\mathbf x_0'(\mathbf X'\mathbf X)^{-1}\mathbf x_0},\\ y_0&:\ \hat y_0\pm t_{\alpha/2,n-p}\sqrt{\hat\sigma^2\left[1+\mathbf x_0'(\mathbf X'\mathbf X)^{-1}\mathbf x_0\right]}. \end{aligned} \tag{7.6}\]
Example 7.2 For Example 4.1, test each coefficient and find 95% confidence intervals.
Solution
\(\hat\sigma^2=2.829\), and the diagonal of \((\mathbf X'\mathbf X)^{-1}\) is \((0.9748,\ 0.1621,\ 0.0836)\). With \(t_{0.025,9}=2.262\):
| Coefficient | Estimate | \(C_{jj}\) | SE | \(t\) | 95% CI |
|---|---|---|---|---|---|
| \(\beta_0\) | 5.3754 | 0.9748 | 1.6605 | 3.237 | (1.619, 9.132) |
| \(\beta_1\) | 3.0118 | 0.1621 | 0.6771 | 4.448 | (1.480, 4.544) |
| \(\beta_2\) | -1.2855 | 0.0836 | 0.4863 | -2.643 | (-2.386, -0.185) |
All \(|t|>2.262\): each regressor contributes significantly given the other. Neither interval for a slope contains zero.
7.5 Simultaneous confidence intervals and joint confidence region
The intervals of Equation 7.5 each have coverage \(1-\alpha\) individually, but the probability that all of them are simultaneously correct is smaller. Two remedies are used.
Joint confidence region
Since \((\hat{\boldsymbol\beta}-\boldsymbol\beta)'\mathbf X'\mathbf X(\hat{\boldsymbol\beta}-\boldsymbol\beta)/\sigma^2\sim\chi^2_p\) independently of \((n-p)MS_{Res}/\sigma^2\sim\chi^2_{n-p}\),
\[\frac{(\hat{\boldsymbol\beta}-\boldsymbol\beta)'\mathbf X'\mathbf X(\hat{\boldsymbol\beta}-\boldsymbol\beta)}{p\,MS_{Res}}\sim F_{p,\,n-p}\]
\[\Rightarrow\ P\left[\frac{(\hat{\boldsymbol\beta}-\boldsymbol\beta)'\mathbf X'\mathbf X(\hat{\boldsymbol\beta}-\boldsymbol\beta)}{p\,MS_{Res}}\le F_\alpha(p,n-p)\right]=1-\alpha.\]
Hence the \(100(1-\alpha)\%\) joint confidence region for all the parameters in \(\boldsymbol\beta\) is the ellipsoid
\[\frac{(\hat{\boldsymbol\beta}-\boldsymbol\beta)'\mathbf X'\mathbf X(\hat{\boldsymbol\beta}-\boldsymbol\beta)}{p\,MS_{Res}}\le F_\alpha(p,\,n-p). \tag{7.7}\]
For a subset of \(q\) parameters \(\boldsymbol\beta_2\) the region is \((\hat{\boldsymbol\beta}_2-\boldsymbol\beta_2)'\mathbf C_{22}^{-1}(\hat{\boldsymbol\beta}_2-\boldsymbol\beta_2)/(q\,MS_{Res})\le F_\alpha(q,n-p)\), where \(\mathbf C_{22}\) is the corresponding block of \((\mathbf X'\mathbf X)^{-1}\). For two slopes this is an ellipse; its tilt reflects the correlation between the estimates.
Bonferroni and Scheffé intervals
For \(g\) intervals with joint coverage at least \(1-\alpha\), the Bonferroni intervals replace \(t_{\alpha/2,n-p}\) in Equation 7.5 by \(t_{\alpha/(2g),n-p}\). The Scheffé intervals, valid for all linear combinations, use \(\sqrt{p\,F_\alpha(p,n-p)}\); they are the projections of the ellipsoid Equation 7.7 on the coordinate axes.
Figure 7.1 shows that the joint region is a narrow, tilted ellipse: because \(x_1\) and \(x_2\) are highly correlated, \(\hat\beta_1\) and \(\hat\beta_2\) are strongly negatively correlated, and combinations of \((\beta_1,\beta_2)\) inside the rectangle of individual intervals may lie outside the joint region.
7.6 Coefficient of determination (\(R^2\))
\(R\) is the multiple correlation coefficient between \(y\) and \(x_1,x_2,\ldots,x_k\) (equivalently between \(y\) and \(\hat y\)), and \(R^2\) is the coefficient of determination. It is a measure of goodness of fit: it describes how well the sample regression fits the observed data.
\[R^2=1-\frac{\mathbf e'\mathbf e}{\sum_{i=1}^n(y_i-\bar y)^2}=1-\frac{SS_{Res}}{SS_T}=\frac{SS_R}{SS_T},\qquad 0\le R^2\le1. \tag{7.8}\]
\(R^2=0\) indicates a poor fit (the regressors explain nothing), and \(R^2=1\) a perfect fit.
7.6.1 Adjusted \(R^2\)
If more explanatory variables are added to the model, \(R^2\) increases (it cannot decrease) even if the added variables are irrelevant, because \(SS_{Res}\) can only fall. The adjusted \(R^2\) (\(\bar R^2\) or \(R^2_{adj}\)) divides each sum of squares by its degrees of freedom:
\[\bar R^2=1-\frac{SS_{Res}/(n-p)}{SS_T/(n-1)}=1-\left(\frac{n-1}{n-p}\right)(1-R^2). \tag{7.9}\]
\(\bar R^2\) increases when a variable is added only if its \(|t|>1\), so it penalizes unnecessary regressors. Adjusted \(R^2\) can be negative: for example, with \(p=3\), \(n=10\) and \(R^2=0.16\),
\[\bar R^2=1-\frac{9}{7}(0.84)=1-1.08=-0.08,\]
which has no interpretation as a proportion of variation explained.
7.6.2 Limitations of \(R^2\)
- If the intercept is absent from the model, \(R^2\) cannot be defined in the usual way: Equation 7.2 no longer holds with the corrected total, and software then reports an uncorrected \(R^2=\hat{\boldsymbol\beta}'\mathbf X'\mathbf y/\mathbf y'\mathbf y\) that is not comparable with the usual one.
- \(R^2\) is sensitive to extreme values; it lacks robustness. A single remote point can make \(R^2\) very large or very small (Chapter 9).
- \(R^2\) always increases with the number of variables, so it cannot be used to choose between models of different size.
- \(R^2\) depends on the range of the regressors: the same relation looks stronger when \(x\) is spread more widely.
- A high \(R^2\) does not mean that the model is correct (a straight line fitted to a curve can have \(R^2>0.9\)) nor that it will predict well.
7.6.3 Relationship between \(F\) and \(R^2\)
\[\begin{aligned} F&=\frac{MS_R}{MS_{Res}}=\frac{(n-p)\,SS_R}{(p-1)\,SS_{Res}}=\frac{n-p}{p-1}\cdot\frac{SS_R}{SS_T-SS_R}\\ &=\frac{n-p}{p-1}\cdot\frac{SS_R/SS_T}{1-SS_R/SS_T}=\frac{n-p}{p-1}\cdot\frac{R^2}{1-R^2}. \end{aligned} \tag{7.10}\]
So \(F\) is an increasing function of \(R^2\): when \(R^2=0\), \(F=0\); as \(R^2\to1\), \(F\to\infty\). The \(F\) test of Table 7.1 is therefore also a test of \(H_0:\rho_{y\cdot x_1\ldots x_k}=0\) (Equation 2.15).
Example 7.3 For Example 4.1, \(R^2=139.541/165.000=0.8457\), so the two regressors explain 84.6% of the variation in \(y\). By Equation 7.9, \(\bar R^2=1-\frac{11}{9}(1-0.8457)=0.8114\). Check with Equation 7.10: \(F=\frac{9}{2}\cdot\frac{0.8457}{0.1543}=24.66\), as in Table 7.2.
7.7 Testing general linear hypotheses (sub-hypotheses)
Many questions concern a subset of the coefficients or relations among them. For example: do phosphorus and potassium jointly contribute to yield after nitrogen is in the model (\(\beta_P=\beta_K=0\))? Are the effects of P and K equal (\(\beta_P=\beta_K\))? Such sub-hypotheses are written as
\[H_0:\mathbf C\boldsymbol\beta=\mathbf d,\]
where \(\mathbf C\) is a \(q\times p\) matrix of rank \(q\) and \(\mathbf d\) a \(q\times1\) vector of constants.
The Wald form
Under \(H_0\), \(\mathbf C\hat{\boldsymbol\beta}-\mathbf d\sim N\left(\mathbf 0,\sigma^2\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C'\right)\), and
\[F=\frac{(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)'\left[\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C'\right]^{-1}(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)/q}{MS_{Res}}\sim F_{q,\,n-p}. \tag{7.11}\]
The extra sum of squares principle
Equivalently, fit the full model (FM) and the reduced model (RM) obtained by imposing \(H_0\). The increase in residual sum of squares when the constraints are imposed is the extra sum of squares:
\[F=\frac{\left[SS_{Res}(RM)-SS_{Res}(FM)\right]/q}{SS_{Res}(FM)/(n-p)}\sim F_{q,\,n-p}. \tag{7.12}\]
When \(H_0\) sets a subset \(\boldsymbol\beta_2\) of \(q\) coefficients to zero, partition \(\mathbf X\boldsymbol\beta=\mathbf X_1\boldsymbol\beta_1+\mathbf X_2\boldsymbol\beta_2\). The extra sum of squares
\[SS_R(\boldsymbol\beta_2\mid\boldsymbol\beta_1)=SS_R(\boldsymbol\beta_1,\boldsymbol\beta_2)-SS_R(\boldsymbol\beta_1)\]
measures the contribution of \(\mathbf X_2\) given that \(\mathbf X_1\) is already in the model, and the test is called the partial \(F\) test. Adding regressors one at a time gives the sequential (Type I) sums of squares printed by anova() in R; they add up to \(SS_R\) but depend on the order of entry. The extra sum of squares for each regressor entered last is the partial (Type II/III for main effects) sum of squares, and its \(F\) equals \(t^2\) of Equation 7.4.
7.8 Partial regression coefficients
In \(y=\beta_0+\beta_1x_1+\cdots+\beta_kx_k+\varepsilon\), \(\beta_j\) is called a partial regression coefficient: it measures the change in the mean of \(y\) for a unit change in \(x_j\) when all other regressors are held constant. The Frisch–Waugh result makes this precise: \(\hat\beta_j\) equals the slope of the simple regression (through the origin) of the residuals of \(y\) on the other regressors against the residuals of \(x_j\) on the other regressors. A plot of these two sets of residuals, the added variable plot or partial regression plot, shows the partial relation of \(y\) with \(x_j\) and reveals points that are influential for \(\hat\beta_j\).
7.9 Restricted least squares
Sometimes prior knowledge requires the coefficients to satisfy exact linear restrictions \(\mathbf C\boldsymbol\beta=\mathbf d\) (for example constant returns to scale in a Cobb–Douglas production function, \(\beta_1+\beta_2=1\)). The restricted least squares estimator minimizes \((\mathbf y-\mathbf X\boldsymbol\beta)'(\mathbf y-\mathbf X\boldsymbol\beta)\) subject to \(\mathbf C\boldsymbol\beta=\mathbf d\). Using a vector \(\boldsymbol\lambda\) of Lagrange multipliers,
\[\phi=(\mathbf y-\mathbf X\boldsymbol\beta)'(\mathbf y-\mathbf X\boldsymbol\beta)-2\boldsymbol\lambda'(\mathbf C\boldsymbol\beta-\mathbf d).\]
Setting \(\partial\phi/\partial\boldsymbol\beta=-2\mathbf X'\mathbf y+2\mathbf X'\mathbf X\boldsymbol\beta-2\mathbf C'\boldsymbol\lambda=\mathbf 0\) gives \(\boldsymbol\beta=\hat{\boldsymbol\beta}+(\mathbf X'\mathbf X)^{-1}\mathbf C'\boldsymbol\lambda\). Substituting into the restriction \(\mathbf C\boldsymbol\beta=\mathbf d\) and solving for \(\boldsymbol\lambda\):
\[\hat{\boldsymbol\beta}_R=\hat{\boldsymbol\beta}-(\mathbf X'\mathbf X)^{-1}\mathbf C'\left[\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C'\right]^{-1}(\mathbf C\hat{\boldsymbol\beta}-\mathbf d). \tag{7.13}\]
Properties
- \(\hat{\boldsymbol\beta}_R\) satisfies the restrictions exactly: \(\mathbf C\hat{\boldsymbol\beta}_R=\mathbf d\).
- If the restrictions are true, \(\hat{\boldsymbol\beta}_R\) is unbiased and \(V(\hat{\boldsymbol\beta}_R)=\sigma^2\left[(\mathbf X'\mathbf X)^{-1}-(\mathbf X'\mathbf X)^{-1}\mathbf C'\left(\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C'\right)^{-1}\mathbf C(\mathbf X'\mathbf X)^{-1}\right]\), which is smaller than \(V(\hat{\boldsymbol\beta})\): correct prior information improves precision.
- If the restrictions are false, \(\hat{\boldsymbol\beta}_R\) is biased.
- \(SS_{Res}(\hat{\boldsymbol\beta}_R)-SS_{Res}(\hat{\boldsymbol\beta})=(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)'\left[\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C'\right]^{-1}(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)\), which is exactly the numerator of Equation 7.11. Thus the Wald test and the extra sum of squares test are identical, and the restrictions can be tested before they are imposed.
Example 7.4 For 30 paddy farms (csv/paddy.csv) the model \(\text{yield}=\beta_0+\beta_1N+\beta_2P+\beta_3K+\varepsilon\) was fitted (yield in q/ha; N, P, K in kg/ha). (a) Test \(H_0:\beta_2=\beta_3=0\) (P and K contribute nothing once N is in the model). (b) Test \(H_0:\beta_2=\beta_3\) (equal effects of P and K) and obtain the restricted estimates.
Solution
The full model gives \(SS_{Res}(FM)=147.064\) with 26 df and \(MS_{Res}=5.656\).
- The reduced model \(\text{yield}=\beta_0+\beta_1N+\varepsilon\) gives \(SS_{Res}(RM)=197.540\). By Equation 7.12,
\[F=\frac{(197.540-147.064)/2}{5.656}=4.462,\]
which exceeds \(F_{0.05}(2,26)=3.369\) (\(p=0.0216\)). P and K together make a significant contribution.
- Here \(\mathbf C=(0,0,1,-1)\), \(d=0\), \(q=1\). \(\mathbf C\hat{\boldsymbol\beta}=\hat\beta_2-\hat\beta_3=0.0177\). By Equation 7.11, \(F=0.172<F_{0.05}(1,26)=4.225\), so equality of the P and K effects is not rejected. The restricted estimates from Equation 7.13 are
\[\hat{\boldsymbol\beta}_R=(27.551,\ 0.0487,\ 0.0687,\ 0.0687)',\]
with \(\hat\beta_{2R}=\hat\beta_{3R}\). The same estimates are obtained by regressing yield on N and the combined variable \((P+K)\).
7.10 R practical
d12 <- read.csv("csv/notes12.csv")
fit <- lm(y ~ x1 + x2, data = d12)
summary(fit) # t tests, R^2, adjusted R^2, overall F#>
#> Call:
#> lm(formula = y ~ x1 + x2, data = d12)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -3.5915 -0.7157 0.1349 0.9562 2.0284
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 5.3754 1.6605 3.237 0.0102 *
#> x1 3.0118 0.6771 4.448 0.0016 **
#> x2 -1.2855 0.4863 -2.643 0.0268 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 1.682 on 9 degrees of freedom
#> Multiple R-squared: 0.8457, Adjusted R-squared: 0.8114
#> F-statistic: 24.66 on 2 and 9 DF, p-value: 0.0002226
anova(fit) # sequential (Type I) SS#> Analysis of Variance Table
#>
#> Response: y
#> Df Sum Sq Mean Sq F value Pr(>F)
#> x1 1 119.774 119.774 42.341 0.0001105 ***
#> x2 1 19.767 19.767 6.988 0.0267608 *
#> Residuals 9 25.459 2.829
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
confint(fit) # individual 95% CIs#> 2.5 % 97.5 %
#> (Intercept) 1.618995 9.1317933
#> x1 1.480148 4.5435109
#> x2 -2.385547 -0.1854314
confint(fit, level = 1 - 0.05 / 2) # Bonferroni for the two slopes (approx.)#> 1.25 % 98.75 %
#> (Intercept) 0.9168305 9.83395815
#> x1 1.1938389 4.82982039
#> x2 -2.5911748 0.02019685
predict(fit, data.frame(x1 = 5, x2 = 8), interval = "confidence")#> fit lwr upr
#> 1 10.15063 8.246774 12.05449
predict(fit, data.frame(x1 = 5, x2 = 8), interval = "prediction")#> fit lwr upr
#> 1 10.15063 5.89616 14.4051
pd <- read.csv("csv/paddy.csv")
full <- lm(yield ~ N + P + K, data = pd)
red <- lm(yield ~ N, data = pd)
anova(red, full) # extra SS test of beta_P = beta_K = 0#> Analysis of Variance Table
#>
#> Model 1: yield ~ N
#> Model 2: yield ~ N + P + K
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 28 197.54
#> 2 26 147.06 2 50.475 4.4619 0.02158 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# General linear hypothesis C beta = d by hand
C <- matrix(c(0, 0, 1, -1), nrow = 1); d <- 0
b <- coef(full); V <- vcov(full) # V = MSres (X'X)^-1
Fw <- t(C %*% b - d) %*% solve(C %*% V %*% t(C)) %*% (C %*% b - d) / nrow(C)
Fw; pf(Fw, 1, df.residual(full), lower.tail = FALSE)#> [,1]
#> [1,] 0.1724146
#> [,1]
#> [1,] 0.6813815
car::linearHypothesis(full, "P = K") # the same test with the car package#> Linear hypothesis test
#>
#> Hypothesis:
#> P - K = 0
#>
#> Model 1: restricted model
#> Model 2: yield ~ N + P + K
#>
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 27 148.04
#> 2 26 147.06 1 0.97523 0.1724 0.6814
# Restricted least squares
XtXi <- solve(crossprod(model.matrix(full)))
bR <- b - XtXi %*% t(C) %*% solve(C %*% XtXi %*% t(C)) %*% (C %*% b - d)
round(drop(bR), 4)#> (Intercept) N P K
#> 27.5509 0.0487 0.0687 0.0687
coef(lm(yield ~ N + I(P + K), data = pd)) # same restricted fit#> (Intercept) N I(P + K)
#> 27.55092949 0.04865098 0.06867411
car::avPlots(full) # added variable (partial regression) plots
Fisher’s analysis of variance for regression
R. A. Fisher introduced the analysis of variance at Rothamsted in the early 1920s, first for field experiments and then, in Statistical Methods for Research Workers (1925), for regression. He showed that the significance of a regression could be judged by comparing the variance it explains with the residual variance, and derived the distribution of their ratio. In Fisher’s honour, George Snedecor at Iowa State College tabulated this distribution in 1934 and named it \(F\). The extra sum of squares principle, which underlies every partial \(F\) test in this chapter, is a direct descendant of Fisher’s idea.
“The analysis of variance is not a mathematical theorem, but rather a convenient method of arranging the arithmetic.”
- R. A. Fisher
7.11 Practical exercises
7.11.1 Practical 7.1: Wheat yield, nitrogen and irrigation
Grain yield of wheat (t/ha) from ten plots receiving different nitrogen doses (kg/ha) and numbers of irrigations is given below. (a) Fit \(y=\beta_0+\beta_1N+\beta_2I+\varepsilon\) and test the overall regression. (b) Test each coefficient and give 95% confidence intervals. (c) Compute \(R^2\) and adjusted \(R^2\). (d) Test whether irrigation contributes after nitrogen, using the extra sum of squares.
| Plot | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| N | 40 | 60 | 80 | 100 | 120 | 40 | 60 | 80 | 100 | 120 |
| Irrigations | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 |
| Yield | 2.9 | 3.4 | 3.9 | 4.1 | 4.8 | 3.6 | 4.0 | 4.6 | 4.9 | 5.5 |
Solution
- The fitted model is \(\hat y=1.770+0.0160N+0.2800I\).
| Source | SS | df | MS | \(F\) |
|---|---|---|---|---|
| Regression | 5.4080 | 2 | 2.7040 | 167.50 |
| Residual | 0.1130 | 7 | 0.01614 | |
| Total | 5.5210 | 9 |
\(F=167.50>F_{0.05}(2,7)=4.74\): the regression is significant.
- With \(t_{0.025,7}=2.365\):
| Estimate | SE | \(t\) | 95% CI | |
|---|---|---|---|---|
| Intercept | 1.7700 | 0.1372 | 12.90 | (1.445, 2.095) |
| N | 0.0160 | 0.0016 | 9.75 | (0.0121, 0.0199) |
| Irrigations | 0.2800 | 0.0328 | 8.54 | (0.2024, 0.3576) |
\(R^2=5.4080/5.5210=0.9795\) and \(\bar R^2=1-\frac{9}{7}(1-0.9795)=0.9737\).
Without irrigation, \(SS_{Res}=1.2890\). By Equation 7.12, \(F=\dfrac{1.2890-0.1130}{0.01614}=72.85\) on (1, 7) df, which equals \(t^2\) for irrigation (\(8.54^2\)). Irrigation makes a significant additional contribution.
Doing it in R
wheat <- data.frame(N = rep(c(40, 60, 80, 100, 120), 2),
I = c(2, 2, 3, 3, 4, 4, 5, 5, 6, 6),
y = c(2.9, 3.4, 3.9, 4.1, 4.8, 3.6, 4.0, 4.6, 4.9, 5.5))
full <- lm(y ~ N + I, data = wheat)
summary(full) # t tests, R^2, adjusted R^2, overall F#>
#> Call:
#> lm(formula = y ~ N + I, data = wheat)
#>
#> Residuals:
#> Min 1Q Median 3Q Max
#> -0.15 -0.10 0.00 0.10 0.15
#>
#> Coefficients:
#> Estimate Std. Error t value Pr(>|t|)
#> (Intercept) 1.77000 0.13723 12.898 3.91e-06 ***
#> N 0.01600 0.00164 9.755 2.52e-05 ***
#> I 0.28000 0.03281 8.535 6.01e-05 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.1271 on 7 degrees of freedom
#> Multiple R-squared: 0.9795, Adjusted R-squared: 0.9737
#> F-statistic: 167.5 on 2 and 7 DF, p-value: 1.227e-06
confint(full)#> 2.5 % 97.5 %
#> (Intercept) 1.44549175 2.09450825
#> N 0.01212138 0.01987862
#> I 0.20242769 0.35757231
anova(lm(y ~ N, data = wheat), full) # extra sum of squares for irrigation#> Analysis of Variance Table
#>
#> Model 1: y ~ N
#> Model 2: y ~ N + I
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 8 1.289
#> 2 7 0.113 1 1.176 72.85 6.015e-05 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
7.11.2 Practical 7.2: Restricted least squares
For the wheat data, suppose agronomic experience suggests that one extra irrigation is worth as much as 10 kg N/ha, i.e. \(\beta_2=10\beta_1\). Test this restriction and obtain the restricted estimates.
Solution
The restriction is \(\mathbf C\boldsymbol\beta=0\) with \(\mathbf C=(0,\ -10,\ 1)\). \(\mathbf C\hat{\boldsymbol\beta}=0.1200\), and by Equation 7.11, \(F=7.646\) on (1, 7) df (\(p=0.028\)), so the restriction is rejected. By Equation 7.13 the restricted estimates are \(\hat{\boldsymbol\beta}_R=(1.8386,\ 0.01943,\ 0.1943)'\), which satisfy \(\hat\beta_{2R}=10\hat\beta_{1R}\) exactly.
Doing it in R
C <- matrix(c(0, -10, 1), nrow = 1)
bw <- coef(full); Ai <- solve(crossprod(model.matrix(full)))
bR <- bw - Ai %*% t(C) %*% solve(C %*% Ai %*% t(C)) %*% (C %*% bw)
drop(bR)#> (Intercept) N I
#> 1.83857143 0.01942857 0.19428571
car::linearHypothesis(full, "I = 10*N") # F test of the restriction#> Linear hypothesis test
#>
#> Hypothesis:
#> - 10 N + I = 0
#>
#> Model 1: restricted model
#> Model 2: y ~ N + I
#>
#> Res.Df RSS Df Sum of Sq F Pr(>F)
#> 1 8 0.23643
#> 2 7 0.11300 1 0.12343 7.646 0.02789 *
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
coef(lm(y ~ I(N + 10 * I), data = wheat)) # same restricted fit#> (Intercept) I(N + 10 * I)
#> 1.83857143 0.01942857
7.12 Chapter Summary
Fill in the blanks
Answers are given at the end of the chapter.
The overall \(F\) test of regression tests \(H_0:\) __________.
In the regression ANOVA, the regression and residual degrees of freedom are __________ and __________.
\(\hat{\boldsymbol\beta}\) and \(\hat\sigma^2\) are independent because \((\mathbf X'\mathbf X)^{-1}\mathbf X'(\mathbf I-\mathbf H)=\) __________.
\(SE(\hat\beta_j)=\) __________.
The joint confidence region for \(\boldsymbol\beta\) has the shape of an __________.
\(R^2=1-\) __________.
Adjusted \(R^2\) can be __________.
In terms of \(R^2\), \(F=\) __________.
The increase in \(SS_{Res}\) when restrictions are imposed is called the __________ sum of squares.
If the restrictions are true, restricted least squares estimates have __________ variance than unrestricted ones.
Short-answer questions
Show that \(\hat{\boldsymbol\beta}\) and \(\hat\sigma^2\) are independently distributed under normality.
Construct the ANOVA table for testing the significance of regression.
What is the difference between the overall \(F\) test and the \(t\) tests of individual coefficients?
Derive the confidence interval for \(\beta_j\).
Why are simultaneous confidence intervals needed? Describe two methods.
Define \(R^2\) and adjusted \(R^2\). Why is the adjusted form preferred for comparing models?
State the limitations of \(R^2\).
Derive the relation between \(F\) and \(R^2\).
Explain the extra sum of squares principle and the partial \(F\) test.
Derive the restricted least squares estimator.
What is a partial regression coefficient? Explain the added variable plot.
Distinguish between sequential and partial sums of squares.
Numerical and conceptual questions
Answers are given at the end of the chapter.
A regression with \(n=25\) and three regressors gave \(SS_R=360\) and \(SS_{Res}=210\). Construct the ANOVA table and test the regression.
For Question 1, find \(R^2\) and \(\bar R^2\).
\(\hat\beta_2=1.8\), \(\hat\sigma^2=4\), \(C_{22}=0.09\), \(n=20\), \(p=4\). Test \(H_0:\beta_2=0\) and find the 95% CI.
A model has \(R^2=0.64\) with \(n=30\), \(p=5\). Find \(F\).
Find \(\bar R^2\) when \(n=12\), \(p=6\), \(R^2=0.40\).
The full model with 5 parameters has \(SS_{Res}=120\) (\(n=35\)); dropping two regressors gives \(SS_{Res}=150\). Test whether the two regressors are needed.
For a Cobb–Douglas function \(\ln y=\beta_0+\beta_1\ln L+\beta_2\ln K\), write \(\mathbf C\) and \(\mathbf d\) for constant returns to scale.
Show that \(t^2=F\) for testing a single coefficient by the extra sum of squares.
How many Bonferroni intervals at overall 95% confidence would use \(t_{0.005}\)?
Using Example 7.2, are the individual 95% intervals for \(\beta_1\) and \(\beta_2\) jointly valid at 95%? Explain with Figure 7.1.
Important formulae
Distribution of the estimator:
\[ \hat{\boldsymbol\beta}\sim N_p\left(\boldsymbol\beta,\sigma^2(\mathbf X'\mathbf X)^{-1}\right) \]
Partition of sums of squares:
\[ SS_T=\mathbf y'\mathbf y-n\bar y^2,\quad SS_R=\hat{\boldsymbol\beta}'\mathbf X'\mathbf y-n\bar y^2,\quad SS_{Res}=\mathbf y'\mathbf y-\hat{\boldsymbol\beta}'\mathbf X'\mathbf y \]
Overall \(F\) test:
\[ F=\frac{SS_R/(p-1)}{SS_{Res}/(n-p)}\sim F_{p-1,n-p} \]
Test and interval for one coefficient:
\[ t=\frac{\hat\beta_j}{\sqrt{\hat\sigma^2C_{jj}}}\sim t_{n-p},\qquad \hat\beta_j\pm t_{\alpha/2,n-p}\sqrt{\hat\sigma^2C_{jj}} \]
Joint confidence region:
\[ \frac{(\hat{\boldsymbol\beta}-\boldsymbol\beta)'\mathbf X'\mathbf X(\hat{\boldsymbol\beta}-\boldsymbol\beta)}{p\,MS_{Res}}\le F_\alpha(p,n-p) \]
\(R^2\), adjusted \(R^2\) and \(F\):
\[ R^2=\frac{SS_R}{SS_T},\qquad\bar R^2=1-\frac{n-1}{n-p}(1-R^2),\qquad F=\frac{n-p}{p-1}\cdot\frac{R^2}{1-R^2} \]
General linear hypothesis:
\[ F=\frac{(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)'[\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C']^{-1}(\mathbf C\hat{\boldsymbol\beta}-\mathbf d)/q}{MS_{Res}}\sim F_{q,n-p} \]
Restricted least squares:
\[ \hat{\boldsymbol\beta}_R=\hat{\boldsymbol\beta}-(\mathbf X'\mathbf X)^{-1}\mathbf C'[\mathbf C(\mathbf X'\mathbf X)^{-1}\mathbf C']^{-1}(\mathbf C\hat{\boldsymbol\beta}-\mathbf d) \]
Quick revision
- Overall \(F\) → is any slope non-zero? df \((p-1,\,n-p)\).
- \(t\) test → contribution of \(x_j\) given all others; \(t^2=\) partial \(F\).
- CI for \(\beta_j\) → \(\hat\beta_j\pm t\sqrt{\hat\sigma^2C_{jj}}\); joint region → ellipsoid with \(F_\alpha(p,n-p)\).
- \(R^2\) never decreases with more regressors; \(\bar R^2\) penalizes them and can be negative.
- \(F=\frac{n-p}{p-1}\frac{R^2}{1-R^2}\).
- Sub-hypothesis \(\mathbf C\boldsymbol\beta=\mathbf d\) → Wald \(F\) = extra SS \(F\).
- Restricted LS → exact restrictions via Lagrange multipliers; more precise if restrictions are true.
Answers to fill in the blanks
1. \(\beta_1=\cdots=\beta_{p-1}=0\) 2. \(p-1\); \(n-p\) 3. \(\mathbf 0\) 4. \(\sqrt{\hat\sigma^2C_{jj}}\) 5. Ellipsoid 6. \(SS_{Res}/SS_T\) 7. Negative 8. \(\frac{n-p}{p-1}\cdot\frac{R^2}{1-R^2}\) 9. Extra 10. Smaller
Solutions to numerical and conceptual questions
\(p=4\). \(MS_R=360/3=120\), \(MS_{Res}=210/21=10\), \(F=12.0>F_{0.05}(3,21)=3.07\); the regression is significant (Equation 7.3).
\(R^2=360/570=0.632\); \(\bar R^2=1-\frac{24}{21}(0.368)=0.579\).
\(SE=\sqrt{4\times0.09}=0.6\), \(t=3.0>t_{0.025,16}=2.120\); reject \(H_0\). CI: \(1.8\pm2.120(0.6)=(0.528,\ 3.072)\) (Equation 7.5).
By Equation 7.10, \(F=\frac{25}{4}\cdot\frac{0.64}{0.36}=11.11\).
\(\bar R^2=1-\frac{11}{6}(0.60)=-0.10\).
By Equation 7.12, \(F=\dfrac{(150-120)/2}{120/30}=3.75>F_{0.05}(2,30)=3.32\); the two regressors are needed.
\(\mathbf C=(0,1,1)\), \(d=1\).
With \(q=1\) and \(\mathbf C=\mathbf e_j'\), Equation 7.11 becomes \(F=\hat\beta_j^2/(C_{jj}MS_{Res})=t^2\).
\(\alpha/(2g)=0.005\) with \(\alpha=0.05\) gives \(g=5\) intervals.
No. Each interval has 95% coverage separately; jointly the coverage is lower. The ellipse is narrow and tilted, so points inside the rectangle of individual intervals can lie outside the 95% joint region.