3  Simple Linear Regression

The simple linear regression model relates a response \(y\) to a single regressor \(x\) by a straight line. Although real problems usually involve several regressors, the simple model is worth studying in detail because every idea of the general theory (least squares, the partition of the total sum of squares, \(t\) and \(F\) tests, confidence and prediction intervals, \(R^2\)) appears here in a form that can be computed by hand (Draper and Smith 1998; Montgomery, Peck, and Vining 2021).

3.1 The model

\[y_i=\beta_0+\beta_1x_i+\varepsilon_i,\qquad i=1,2,\ldots,n \tag{3.1}\]

where \(\beta_0\) (intercept) is the mean of \(y\) when \(x=0\), \(\beta_1\) (slope or regression coefficient) is the change in the mean of \(y\) per unit increase in \(x\), and the errors satisfy \(E(\varepsilon_i)=0\), \(V(\varepsilon_i)=\sigma^2\) and \(Cov(\varepsilon_i,\varepsilon_j)=0\) for \(i\neq j\). Hence \(E(y_i)=\beta_0+\beta_1x_i\) and \(V(y_i)=\sigma^2\).

3.2 Least squares estimation

The least squares estimates minimize

\[S(\beta_0,\beta_1)=\sum_{i=1}^n(y_i-\beta_0-\beta_1x_i)^2.\]

Setting \(\partial S/\partial\beta_0=0\) and \(\partial S/\partial\beta_1=0\) gives the normal equations

\[n\hat\beta_0+\hat\beta_1\sum x_i=\sum y_i,\qquad \hat\beta_0\sum x_i+\hat\beta_1\sum x_i^2=\sum x_iy_i, \tag{3.2}\]

whose solution is

\[\hat\beta_1=\frac{S_{xy}}{S_{xx}}=\frac{\sum(x_i-\bar x)(y_i-\bar y)}{\sum(x_i-\bar x)^2},\qquad \hat\beta_0=\bar y-\hat\beta_1\bar x. \tag{3.3}\]

The fitted line is \(\hat y=\hat\beta_0+\hat\beta_1x\), and the residuals are \(e_i=y_i-\hat y_i\).

Properties of the fitted line

  1. \(\sum e_i=0\) (from the first normal equation), so the line passes through \((\bar x,\bar y)\).
  2. \(\sum x_ie_i=0\) and \(\sum\hat y_ie_i=0\): residuals are orthogonal to the regressor and to the fitted values.
  3. \(\sum y_i=\sum\hat y_i\).

3.3 Properties of the estimators

Write \(\hat\beta_1=\sum c_iy_i\) with \(c_i=(x_i-\bar x)/S_{xx}\). Since \(\sum c_i=0\) and \(\sum c_ix_i=1\),

\[E(\hat\beta_1)=\sum c_i(\beta_0+\beta_1x_i)=\beta_1,\qquad V(\hat\beta_1)=\sigma^2\sum c_i^2=\frac{\sigma^2}{S_{xx}}. \tag{3.4}\]

Similarly,

\[E(\hat\beta_0)=\beta_0,\qquad V(\hat\beta_0)=\sigma^2\left(\frac1n+\frac{\bar x^2}{S_{xx}}\right),\qquad Cov(\hat\beta_0,\hat\beta_1)=-\frac{\bar x\sigma^2}{S_{xx}}. \tag{3.5}\]

Both estimators are linear in \(y\) and unbiased. The Gauss–Markov theorem (Chapter 5) shows that they have the smallest variance among all linear unbiased estimators. Equation 3.4 also has a practical message for designing experiments: the slope is estimated most precisely when the \(x\) values are spread widely (large \(S_{xx}\)).

3.4 Estimation of \(\sigma^2\) and the analysis of variance

The total variation in \(y\) splits into a part explained by the line and a residual part:

\[\underbrace{\sum(y_i-\bar y)^2}_{SS_T}=\underbrace{\sum(\hat y_i-\bar y)^2}_{SS_R}+\underbrace{\sum(y_i-\hat y_i)^2}_{SS_{Res}} \tag{3.6}\]

with \(SS_T=S_{yy}\), \(SS_R=\hat\beta_1S_{xy}=\hat\beta_1^2S_{xx}\), and \(SS_{Res}=S_{yy}-\hat\beta_1S_{xy}\). Since \(E(SS_{Res})=(n-2)\sigma^2\), an unbiased estimate of \(\sigma^2\) is

\[\hat\sigma^2=MS_{Res}=\frac{SS_{Res}}{n-2}. \tag{3.7}\]

Table 3.1: Analysis of variance for simple linear regression
Source df SS MS \(F\)
Regression 1 \(SS_R\) \(MS_R=SS_R\) \(MS_R/MS_{Res}\)
Residual \(n-2\) \(SS_{Res}\) \(MS_{Res}=SS_{Res}/(n-2)\)
Total \(n-1\) \(SS_T\)

Under \(H_0:\beta_1=0\) and normal errors, \(F\sim F_{1,n-2}\).

3.5 Tests and confidence intervals

With normal errors, \(\hat\beta_1\sim N(\beta_1,\sigma^2/S_{xx})\) and \((n-2)MS_{Res}/\sigma^2\sim\chi^2_{n-2}\) independently, so

\[t=\frac{\hat\beta_1-\beta_{10}}{\sqrt{MS_{Res}/S_{xx}}}\sim t_{n-2}\quad\text{under }H_0:\beta_1=\beta_{10}. \tag{3.8}\]

For \(\beta_{10}=0\), \(t^2=F\) of Table 3.1. Likewise for the intercept, \(t=(\hat\beta_0-\beta_{00})/\sqrt{MS_{Res}(1/n+\bar x^2/S_{xx})}\). The \(100(1-\alpha)\%\) confidence intervals are

\[\hat\beta_1\pm t_{\alpha/2,n-2}\sqrt{\frac{MS_{Res}}{S_{xx}}},\qquad \hat\beta_0\pm t_{\alpha/2,n-2}\sqrt{MS_{Res}\left(\frac1n+\frac{\bar x^2}{S_{xx}}\right)}. \tag{3.9}\]

3.5.1 Mean response and prediction of a new observation

At a given \(x_0\), the estimated mean response \(\hat\mu_0=\hat\beta_0+\hat\beta_1x_0\) has variance \(\sigma^2\left[\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]\). A new observation \(y_0\) at \(x_0\) carries its own error, so the prediction error \(y_0-\hat y_0\) has variance \(\sigma^2\left[1+\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]\). Hence

\[\text{CI for }E(y\mid x_0):\ \hat y_0\pm t_{\alpha/2,n-2}\sqrt{MS_{Res}\left[\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]} \tag{3.10}\]

\[\text{PI for }y_0:\ \hat y_0\pm t_{\alpha/2,n-2}\sqrt{MS_{Res}\left[1+\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]} \tag{3.11}\]

Both intervals are narrowest at \(x_0=\bar x\) and widen as \(x_0\) moves away, which is another reason to avoid extrapolation.

3.6 Coefficient of determination

\[R^2=\frac{SS_R}{SS_T}=1-\frac{SS_{Res}}{SS_T} \tag{3.12}\]

is the proportion of the variation in \(y\) explained by the regression. In simple linear regression \(R^2=r_{xy}^2\).

Example 3.1 Rice grain yield (t/ha) at ten nitrogen doses (kg/ha) is given in Table 3.2 (csv/nitrogen.csv). Fit a simple linear regression, test its significance, obtain 95% confidence intervals for the coefficients and predict the yield at 100 kg N/ha.

Table 3.2: Nitrogen dose and rice grain yield
Sl No. N (kg/ha), \(x\) Yield (t/ha), \(y\) \(x-\bar x\) \(y-\bar y\) \((x-\bar x)^2\) \((x-\bar x)(y-\bar y)\)
1 0 2.8 -90 -1.590 8100 143.100
2 20 3.1 -70 -1.290 4900 90.300
3 40 3.6 -50 -0.790 2500 39.500
4 60 3.9 -30 -0.490 900 14.700
5 80 4.3 -10 -0.090 100 0.900
6 100 4.5 10 0.110 100 1.100
7 120 5.0 30 0.610 900 18.300
8 140 5.2 50 0.810 2500 40.500
9 160 5.6 70 1.210 4900 84.700
10 180 5.9 90 1.510 8100 135.900

Solution

\(n=10\), \(\bar x=90\), \(\bar y=4.390\), \(S_{xx}=33000\), \(S_{xy}=569.000\) and \(S_{yy}=9.8490\).

By Equation 3.3,

\[\hat\beta_1=\frac{569.000}{33000}=0.01724,\qquad \hat\beta_0=4.390-0.01724\times90=2.8382.\]

The fitted line is \(\hat y=2.8382+0.01724x\): every additional kg of N raises yield by about 17.2 kg/ha within the range studied.

\(SS_R=\hat\beta_1S_{xy}=9.8109\), \(SS_{Res}=9.8490-9.8109=0.0381\), \(MS_{Res}=0.0381/8=0.00476\).

Table 3.3: ANOVA for Example 3.1
Source df SS MS \(F\)
Regression 1 9.8109 9.8109 2062.2
Residual 8 0.0381 0.00476
Total 9 9.8490

\(F=2062.2\) far exceeds \(F_{0.05}(1,8)=5.32\), so the regression is highly significant.

\(SE(\hat\beta_1)=\sqrt{0.00476/33000}=0.00038\) and \(t=0.01724/0.00038=45.41\) (note \(t^2=F\)). With \(t_{0.025,8}=2.306\) the 95% confidence interval for \(\beta_1\) is \((0.01637,\ 0.01812)\). \(SE(\hat\beta_0)=0.0405\) and the interval for \(\beta_0\) is \((2.745,\ 2.932)\).

At \(x_0=100\): \(\hat y_0=4.562\) t/ha. By Equation 3.10 and Equation 3.11 the 95% confidence interval for the mean yield is \(4.562\pm0.051\) and the prediction interval for a single new plot is \(4.562\pm0.167\).

\(R^2=9.8109/9.8490=0.9961\): nitrogen explains 99.6% of the variation in yield.

3.7 Regression through the origin

When theory requires the line to pass through the origin (for example, no harvest when no plants are present), the model \(y_i=\beta_1x_i+\varepsilon_i\) is fitted. Minimizing \(\sum(y_i-\beta_1x_i)^2\) gives

\[\hat\beta_1=\frac{\sum x_iy_i}{\sum x_i^2},\qquad MS_{Res}=\frac{\sum(y_i-\hat\beta_1x_i)^2}{n-1}. \tag{3.13}\]

The residuals no longer sum to zero, and the usual \(R^2\) is not meaningful (Chapter 7). Fit the no-intercept model only when it is justified by theory and the data lie close to the origin.

3.8 The two regression lines

When both variables are random (as in correlation analysis), one may regress \(y\) on \(x\) or \(x\) on \(y\):

\[y-\bar y=b_{yx}(x-\bar x),\quad b_{yx}=r\frac{s_y}{s_x};\qquad x-\bar x=b_{xy}(y-\bar y),\quad b_{xy}=r\frac{s_x}{s_y}.\]

Both lines pass through \((\bar x,\bar y)\), \(b_{yx}b_{xy}=r^2\), and the lines coincide only when \(r=\pm1\). The line of \(y\) on \(x\) is used to predict \(y\) from \(x\); it is not the inverse of the line of \(x\) on \(y\).

3.9 R practical

nt  <- read.csv("csv/nitrogen.csv")
fit <- lm(yield ~ N, data = nt)
summary(fit)          # estimates, SE, t, R^2, F
#> 
#> Call:
#> lm(formula = yield ~ N, data = nt)
#> 
#> Residuals:
#>      Min       1Q   Median       3Q      Max 
#> -0.08303 -0.04954 -0.01758  0.06091  0.09273 
#> 
#> Coefficients:
#>              Estimate Std. Error t value Pr(>|t|)    
#> (Intercept) 2.8381818  0.0405404   70.01 1.93e-12 ***
#> N           0.0172424  0.0003797   45.41 6.11e-11 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 0.06898 on 8 degrees of freedom
#> Multiple R-squared:  0.9961, Adjusted R-squared:  0.9957 
#> F-statistic:  2062 on 1 and 8 DF,  p-value: 6.108e-11
anova(fit)            # ANOVA table
#> Analysis of Variance Table
#> 
#> Response: yield
#>           Df Sum Sq Mean Sq F value    Pr(>F)    
#> N          1 9.8109  9.8109  2062.2 6.108e-11 ***
#> Residuals  8 0.0381  0.0048                      
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
confint(fit)          # 95% CIs for beta0 and beta1
#>                  2.5 %   97.5 %
#> (Intercept) 2.74469543 2.931668
#> N           0.01636684 0.018118
new <- data.frame(N = 100)
predict(fit, new, interval = "confidence")
#>        fit     lwr      upr
#> 1 4.562424 4.51137 4.613479
predict(fit, new, interval = "prediction")
#>        fit      lwr      upr
#> 1 4.562424 4.395374 4.729474
grid <- data.frame(N = seq(0, 180, length.out = 100))
cb <- predict(fit, grid, interval = "confidence")
pb <- predict(fit, grid, interval = "prediction")
plot(yield ~ N, data = nt, pch = 19, col = "darkgreen",
     xlab = "Nitrogen (kg/ha)", ylab = "Grain yield (t/ha)")
abline(fit, lwd = 2)
matlines(grid$N, cb[, 2:3], lty = 2, col = "steelblue")
matlines(grid$N, pb[, 2:3], lty = 3, col = "firebrick")
Figure 3.1: Fitted line with 95% confidence band (dashed) and prediction band (dotted)
Historical Insights

Legendre, Gauss and a priority dispute

When Legendre published least squares in 1805 he gave it a name and showed how to form the normal equations, but no probabilistic justification (Legendre 1805). Gauss, in 1809, derived the method from the assumption of normally distributed errors and later (1821) proved that least squares gives minimum variance linear unbiased estimates without assuming normality (Gauss 1809). Gauss’s claim to have used the method since 1795 annoyed Legendre, who protested in print. Historians now accept both men as independent discoverers.

Quotes to Inspire

“The best thing about being a statistician is that you get to play in everyone’s backyard.”
- John W. Tukey

3.10 Practical exercises

3.10.1 Practical 3.1: Potassium response of cassava

Tuber yield of cassava (t/ha) at six levels of potassium (kg K₂O/ha) is given below. (a) Fit the regression of yield on K. (b) Construct the ANOVA table. (c) Find the 95% confidence interval for the slope. (d) Predict the yield at 60 kg K₂O/ha with 95% confidence and prediction intervals.

Table 3.4: Potassium dose and cassava tuber yield
K₂O (kg/ha), \(x\) 0 25 50 75 100 125
Yield (t/ha), \(y\) 18.2 20.1 22.8 24.0 26.5 27.9

Solution

  1. \(\bar x=62.5\), \(\bar y=23.250\), \(S_{xx}=10937.5\), \(S_{xy}=861.25\), \(S_{yy}=68.3750\). By Equation 3.3, \(\hat\beta_1=861.25/10937.5=0.07874\) and \(\hat\beta_0=23.250-0.07874(62.5)=18.3286\):

\[\hat y=18.329+0.0787x.\]

Each kg of K₂O adds about 79 kg/ha of tubers.

Table 3.5: ANOVA for Practical 3.1
Source df SS MS \(F\)
Regression 1 67.8173 67.8173 486.4
Residual 4 0.5577 0.1394
Total 5 68.3750

\(F\) far exceeds \(F_{0.05}(1,4)=7.71\); \(R^2=0.9918\).

  1. \(SE(\hat\beta_1)=\sqrt{0.1394/10937.5}=0.00357\); with \(t_{0.025,4}=2.776\) the interval is \(0.0787\pm0.0099=(0.0688,\ 0.0887)\).

  2. \(\hat y_0=23.053\) t/ha. By Equation 3.10 and Equation 3.11, CI: \(23.053\pm0.424\); PI: \(23.053\pm1.120\).

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))
fit <- lm(yield ~ K, data = cassava)
summary(fit)
#> 
#> Call:
#> lm(formula = yield ~ K, data = cassava)
#> 
#> Residuals:
#>       1       2       3       4       5       6 
#> -0.1286 -0.1971  0.5343 -0.2343  0.2971 -0.2714 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept) 18.32857    0.27025   67.82 2.83e-07 ***
#> K            0.07874    0.00357   22.05 2.50e-05 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Residual standard error: 0.3734 on 4 degrees of freedom
#> Multiple R-squared:  0.9918, Adjusted R-squared:  0.9898 
#> F-statistic: 486.4 on 1 and 4 DF,  p-value: 2.502e-05
anova(fit)
#> Analysis of Variance Table
#> 
#> Response: yield
#>           Df Sum Sq Mean Sq F value    Pr(>F)    
#> K          1 67.817  67.817  486.39 2.502e-05 ***
#> Residuals  4  0.558   0.139                      
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
confint(fit, "K")
#>        2.5 %     97.5 %
#> K 0.06882984 0.08865588
predict(fit, data.frame(K = 60), interval = "confidence")
#>        fit      lwr      upr
#> 1 23.05314 22.62918 23.47711
predict(fit, data.frame(K = 60), interval = "prediction")
#>        fit      lwr      upr
#> 1 23.05314 21.93307 24.17321
plot(yield ~ K, data = cassava, pch = 19); abline(fit)

3.11 Chapter Summary

Fill in the blanks

Answers are given at the end of the chapter.

  1. The least squares slope in simple linear regression is \(\hat\beta_1=\) __________.

  2. The fitted least squares line always passes through the point __________.

  3. The residuals of a least squares fit with intercept sum to __________.

  4. \(V(\hat\beta_1)=\) __________.

  5. The unbiased estimate of \(\sigma^2\) in simple linear regression has __________ degrees of freedom.

  6. In simple linear regression, the \(F\) statistic for regression equals the square of the __________ statistic for the slope.

  7. The prediction interval for a new observation is always __________ than the confidence interval for the mean response.

  8. Both intervals are narrowest at \(x_0=\) __________.

  9. In simple linear regression, \(R^2\) equals the square of __________.

  10. In regression through the origin, \(\hat\beta_1=\) __________.

Short-answer questions

  1. Write the simple linear regression model and its assumptions.

  2. Derive the normal equations for simple linear regression.

  3. Show that \(\hat\beta_1\) is an unbiased estimator of \(\beta_1\).

  4. Derive \(V(\hat\beta_1)\) and explain its implication for choosing \(x\) values in an experiment.

  5. State the properties of the least squares fitted line.

  6. Show that \(SS_T=SS_R+SS_{Res}\).

  7. Distinguish between a confidence interval for the mean response and a prediction interval.

  8. When is regression through the origin appropriate?

  9. Why are the regression lines of \(y\) on \(x\) and \(x\) on \(y\) different?

  10. Explain the meaning of \(R^2\).

Numerical and conceptual questions

Answers are given at the end of the chapter.

  1. Given \(n=8\), \(\bar x=5\), \(\bar y=20\), \(S_{xx}=42\), \(S_{xy}=84\), \(S_{yy}=200\), find the fitted line.

  2. For Question 1, find \(SS_R\), \(SS_{Res}\), \(MS_{Res}\) and \(R^2\).

  3. For Question 1, test \(H_0:\beta_1=0\).

  4. For Question 1, find the standard error of \(\hat\beta_0\).

  5. For Question 1, find the 95% confidence interval for the mean response at \(x_0=7\).

  6. For Question 1, find the 95% prediction interval for a new observation at \(x_0=7\).

  7. If \(r=0.8\), \(s_x=2\), \(s_y=5\), find \(b_{yx}\) and \(b_{xy}\).

  8. The \(t\) value for the slope is 4.2 in a simple regression with \(n=12\). Find the \(F\) value of the ANOVA.

  9. Why is the residual degrees of freedom \(n-2\)?

  10. If all \(x_i\) are equal, can \(\beta_1\) be estimated? Why?

Important formulae

Least squares estimates:

\[ \hat\beta_1=\frac{S_{xy}}{S_{xx}},\qquad\hat\beta_0=\bar y-\hat\beta_1\bar x \]

Variances of estimates:

\[ V(\hat\beta_1)=\frac{\sigma^2}{S_{xx}},\qquad V(\hat\beta_0)=\sigma^2\left(\frac1n+\frac{\bar x^2}{S_{xx}}\right) \]

Partition of sums of squares:

\[ SS_T=SS_R+SS_{Res},\qquad SS_R=\hat\beta_1S_{xy} \]

Residual mean square:

\[ MS_{Res}=\frac{SS_{Res}}{n-2} \]

Test of slope:

\[ t=\frac{\hat\beta_1}{\sqrt{MS_{Res}/S_{xx}}}\sim t_{n-2} \]

Confidence and prediction intervals at \(x_0\):

\[ \hat y_0\pm t_{\alpha/2,n-2}\sqrt{MS_{Res}\left[\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]},\qquad \hat y_0\pm t_{\alpha/2,n-2}\sqrt{MS_{Res}\left[1+\frac1n+\frac{(x_0-\bar x)^2}{S_{xx}}\right]} \]

Quick revision

  • Least squares → minimize \(\sum(y_i-\beta_0-\beta_1x_i)^2\) → normal equations.
  • Fitted line passes through \((\bar x,\bar y)\); \(\sum e_i=0\).
  • \(\hat\beta_0,\hat\beta_1\) are unbiased; precision improves with larger \(S_{xx}\).
  • \(MS_{Res}\) estimates \(\sigma^2\) with \(n-2\) df.
  • \(t\) test of slope ⇔ \(F\) test of regression (\(t^2=F\)).
  • Prediction interval is wider than confidence interval; both widen away from \(\bar x\).
  • \(R^2=r^2\) in simple regression.

Answers to fill in the blanks

1. \(S_{xy}/S_{xx}\) 2. \((\bar x,\bar y)\) 3. Zero 4. \(\sigma^2/S_{xx}\) 5. \(n-2\) 6. \(t\) 7. Wider 8. \(\bar x\) 9. \(r_{xy}\) 10. \(\sum x_iy_i/\sum x_i^2\)

Solutions to numerical and conceptual questions

  1. By Equation 3.3, \(\hat\beta_1=84/42=2\), \(\hat\beta_0=20-2(5)=10\); \(\hat y=10+2x\).

  2. \(SS_R=2\times84=168\), \(SS_{Res}=200-168=32\), \(MS_{Res}=32/6=5.333\), \(R^2=168/200=0.84\).

  3. By Equation 3.8, \(t=2/\sqrt{5.333/42}=5.612>t_{0.025,6}=2.447\); reject \(H_0\).

  4. \(SE(\hat\beta_0)=\sqrt{5.333(1/8+25/42)}=1.960\).

  5. \(\hat y_0=24\); by Equation 3.10, \(24\pm2.447\sqrt{5.333(0.125+4/42)}=24\pm2.652\), i.e. \((21.35,\ 26.65)\).

  6. By Equation 3.11, \(24\pm2.447\sqrt{5.333(1.125+4/42)}=24\pm6.242\), i.e. \((17.76,\ 30.24)\).

  7. \(b_{yx}=0.8(5/2)=2.0\), \(b_{xy}=0.8(2/5)=0.32\).

  8. \(F=t^2=17.64\) with (1, 10) df.

  9. Two parameters (\(\beta_0,\beta_1\)) are estimated, imposing two linear constraints (\(\sum e_i=0\), \(\sum x_ie_i=0\)) on the residuals.

  10. No. \(S_{xx}=0\), so \(\hat\beta_1=S_{xy}/S_{xx}\) is undefined; the \(\mathbf X\) matrix is not of full rank.