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:
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.
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.
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.
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})$.
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.
The student who revised for $3$ hours scored $53$. Find the residual for this student.
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$.
A student's actual score is $70$ and the regression line predicts $66.5$. Find the residual.
Residual $= 70 - 66.5 = 3.5$. The point is $3.5$ above the line.
The least-squares regression line is the line that makes which quantity as small as possible?
Squared residuals, added up. The plain sum of residuals is always $0$ for the least-squares line, so it can't pick out the best one.
$r = 0.8$, $s_y = 10$ and $s_x = 4$. Find the gradient $b$ of the least-squares line.
$b = 0.8 \times \dfrac{10}{4} = 2$.
$\bar{y} = 50$, $\bar{x} = 10$ and $b = 2$. Find the intercept $a$.
$a = \bar{y} - b\bar{x} = 50 - 20 = 30$.
Which point is always on the least-squares regression line?
From $a = \bar{y} - b\bar{x}$, we get $\bar{y} = a + b\bar{x}$, so the mean point satisfies the equation.
A regression line is $\hat{y} = 12 + 0.8x$. By how much does the predicted $y$ increase when $x$ increases by $5$?
Each unit of $x$ adds $0.8$, so $5$ units add $5 \times 0.8 = 4$.
Use your calculator to find the gradient of the least-squares line for $(1, 3)$, $(2, 5)$, $(3, 4)$, $(4, 8)$.
Linear regression gives $\hat{y} = 1.5 + 1.4x$, so $b = 1.4$.
For the same data, find the intercept $a$.
$\bar{x} = 2.5$ and $\bar{y} = 5$, so $a = 5 - 1.4 \times 2.5 = 1.5$.
Exam style: for $x$: $2, 4, 6, 8, 10$ and $y$: $15, 12, 10, 6, 3$, find the gradient of the least-squares line.
A calculator gives $\hat{y} = 18.2 - 1.5x$. (Check: the line passes through $(\bar{x}, \bar{y}) = (6, 9.2)$, since $18.2 - 9 = 9.2$.)
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$.
$b = -0.75 \times \tfrac{12}{5} = -1.8$ and $a = 65 + 1.8 \times 20 = 101$. At $x = 25$: $\hat{y} = 101 - 45 = 56$.
Coaching Centre