11B

The least-squares regression line

Lines of best fit, residuals, the least-squares regression line and its formulas in terms of r and the standard deviations, the line passing through the mean point, and interpreting the gradient and intercept in context.

A correlation tells you two variables move together. To actually predict one from the other, you need the equation of a line through the data. Everyone drawing a line "by eye" gets a slightly different one, so statisticians agreed on a rule for the single best line: the least-squares line.

Residuals and least squares

A line $\hat{y} = a + bx$ gives a predicted value $\hat{y}$ (read "$y$-hat") for each $x$. The residual of a data point is how far the actual value is from the prediction:

Residual
$$\text{residual} = y - \hat{y} = \text{actual} - \text{predicted}$$

A positive residual means the point is above the line; negative means below. The least-squares regression line is the line that makes the sum of the squared residuals as small as possible. Squaring stops positive and negative residuals cancelling, and punishes big misses more than small ones.

Find the least-squares line

The dots are the revision data from 11A. Adjust the gradient and intercept to make the sum of squared residuals as small as you can.

Try this

Get the sum of squared residuals below $40$. The smallest possible value is about $37.8$. When you are close, look at the height of your line at $x = 4.5$ and compare it with the mean score, $62.375$.

Finding the line

In practice your calculator finds the line directly: enter the data in statistics mode and choose linear regression. It reports $a$, $b$ and $r$. When you are given summary statistics instead of the data, use these formulas.

Least-squares regression line
$$\hat{y} = a + bx \qquad b = r\,\frac{s_y}{s_x} \qquad a = \bar{y} - b\bar{x}$$

Here $\bar{x}$, $\bar{y}$ are the means and $s_x$, $s_y$ the standard deviations of $x$ and $y$. Rearranging the formula for $a$ gives $\bar{y} = a + b\bar{x}$: the line always passes through the mean point $(\bar{x}, \bar{y})$.

Example 1●●

For the revision data in 11A, $\bar{x} = 4.5$, $\bar{y} = 62.375$, $s_x \approx 2.449$, $s_y \approx 9.985$ and $r \approx 0.9725$. Find the least-squares line.

$b = 0.9725 \times \dfrac{9.985}{2.449} \approx 3.96$
Gradient from r and the two standard deviations.
$a = 62.375 - 3.964 \times 4.5 \approx 44.54$
Intercept from the mean point. Use the unrounded b from the calculator memory.
$\hat{y} = 44.54 + 3.96x$
Example 2: a residual●

The student who revised for $3$ hours scored $53$. Find the residual for this student.

$\hat{y} = 44.54 + 3.96 \times 3 \approx 56.4$
Predicted score from the line.
Residual $= 53 - 56.4 = -3.4$. This student scored about $3.4$ marks below the trend.
Actual minus predicted.

Interpreting the line

  • The gradient $b$ is the predicted change in $y$ for each increase of $1$ in $x$. Here: each extra hour of revision is associated with about $4$ more marks.
  • The intercept $a$ is the predicted $y$ when $x = 0$. Here: a student who doesn't revise is predicted to score about $45$. Only interpret it when $x = 0$ makes sense and is near the data.

Your turn

Summary statistics: $\bar{x} = 12$, $\bar{y} = 40$, $s_x = 3$, $s_y = 6$, $r = 0.9$. Find the least-squares line.

Show the working

$b = 0.9 \times \dfrac{6}{3} = 1.8$. $a = 40 - 1.8 \times 12 = 40 - 21.6 = 18.4$. So $\hat{y} = 18.4 + 1.8x$.

Flashcards
Residual
Actual minus predicted: $y - \hat{y}$
Gradient of the least-squares line
$b = r\dfrac{s_y}{s_x}$
Intercept of the least-squares line
$a = \bar{y} - b\bar{x}$
A point always on the line
The mean point $(\bar{x}, \bar{y})$
Practice
  1. A student's actual score is $70$ and the regression line predicts $66.5$. Find the residual.

  2. The least-squares regression line is the line that makes which quantity as small as possible?

  3. $r = 0.8$, $s_y = 10$ and $s_x = 4$. Find the gradient $b$ of the least-squares line.

  4. $\bar{y} = 50$, $\bar{x} = 10$ and $b = 2$. Find the intercept $a$.

  5. Which point is always on the least-squares regression line?

  6. A regression line is $\hat{y} = 12 + 0.8x$. By how much does the predicted $y$ increase when $x$ increases by $5$?

  7. Use your calculator to find the gradient of the least-squares line for $(1, 3)$, $(2, 5)$, $(3, 4)$, $(4, 8)$.

  8. For the same data, find the intercept $a$.

  9. Exam style: for $x$: $2, 4, 6, 8, 10$ and $y$: $15, 12, 10, 6, 3$, find the gradient of the least-squares line.

  10. Exam style: $\bar{x} = 20$, $\bar{y} = 65$, $s_x = 5$, $s_y = 12$ and $r = -0.75$. Find the least-squares line, and use it to predict $y$ when $x = 25$.

Formula sheet