Line of best fit
The dots on a scatter plot climb together, but not along any one straight line. Which line sums them up, and what can it tell you about a case nobody measured?
Where you are 9 in Bivariate data
When you reach for it
A scatter plot puts one dot on the grid for each case: one puppy-week, one evening, one test flight. Often the dots rise or fall together in a band that runs roughly straight, and then a single straight line can stand in for the whole cloud. That line is a line of best fit, also called a trend line: a straight line drawn on a scatter plot to follow the overall pattern of the dots, passing as close to them as it can overall.
Reach for it when the scatter plot looks linear, which is a matter of reading its form, direction and strength, and you want a short summary of the pattern or a prediction for a case nobody measured: the puppy’s mass in the week it was not weighed, a cricket’s chirping rate at a temperature nobody recorded.
Unlike writing a linear rule from a story, where every point sits on the line, real measurements scatter, and the task is choosing a line that misses them by as little as it can.
The lesson takes two parts. Part 1 draws a line by eye and judges between two lines. Part 2 writes the line’s equation, uses it to predict, and asks when a prediction can be trusted.
The procedure
Part 1: drawing a line by eye
First decide whether a line belongs at all. A straight line can only sum up a pattern that is straight. If the dots bend, any straight line runs below them in one stretch and above them in another. If the dots show no pattern, there is nothing for a line to follow.
Lay a straight edge along the band. Turn a clear ruler until it points the way the band runs, then slide it until it sits in the middle of the band. Then ask four things of the line.
Does it follow the trend? A line with the right height in the middle but the wrong tilt is right only in the middle.
Are there about as many dots above it as below? A line with nearly every dot above it is too low: it would underestimate almost every case.
Are the dots above and below mixed along its length? If the dots above all sit at one end and the dots below at the other, the line crosses the band instead of running along it: its tilt is wrong.
Are the gaps small overall? The vertical gap of a dot is the dot’s value minus the line’s value at the same horizontal position. A positive gap means the dot is above the line, a negative one that it is below. The gap is measured vertically, not as the shortest distance to the line, because the line will predict the vertical variable from the horizontal one, and the vertical gap is how far off that prediction would have been for that dot.
The line need not pass through any dot. Its job is to run between the dots, not to visit them. In particular it should not be drawn by joining the first and last dots: those two have their own scatter, and a line built on them inherits it while ignoring every dot in between.
“Best” here means as good as a careful eye can judge: two people’s lines differ a little.
Choosing between two lines. Count the dots above and below each line and look at where they sit. If both lines pass, the line whose dots sit closer to it fits better. When the eye cannot decide, add the sizes of the vertical gaps (ignoring the signs) and compare the totals. The signs must go first: gaps of +5 and -5 are both misses of 5, but added with their signs they cancel to 0.
Part 2: the equation, and predictions
Read two points off the line, not off the data. Once drawn, the line is the model. Pick two points where it crosses gridline intersections exactly, far apart, so a small reading slip barely changes the slope. Then, as for any line through two points, with y = mx + b,
(the slope formula), and b comes from putting either point into y = mx + b and solving. Putting the other point in afterwards is a check.
Predict by substituting. To predict the vertical variable, put the horizontal value into the equation. To go the other way, put the vertical value in and solve. Either way the answer estimates the trend, so it is reported as “about” and rounded sensibly: a single case can land away from the line by about as much as the dots do.
Inside the data or outside it. A prediction at a horizontal value between the smallest and largest measured is interpolation; one outside that stretch is extrapolation. Interpolation has dots on both sides, and the line was checked against them. Extrapolation assumes the straight pattern carries on where nobody measured; the further out it goes, the less it can be trusted, and far enough out the line can give impossible values. Where a model holds: domain, interpolation and extrapolation takes this further.
Worked examples
Examples 1 to 3 go with Part 1 of the lesson, and Examples 4 to 6 with Part 2.
A line by eye through a puppy’s growth
A puppy was weighed once a week from week 8 after its birth to week 18, except for week 17 (made-up data). Each pair is (age in weeks, mass in kilograms): (8, 4.3), (9, 4.4), (10, 5.2), (11, 5.3), (12, 6.2), (13, 6.4), (14, 6.8), (15, 7.7), (16, 7.9) and (18, 9.2). Draw a line of best fit and check it.
The dots rise in a narrow band that runs straight, with no bend and no stray dot, so a line belongs. A ruler turned to the band and slid to its middle gives the line in the figure. It passes through (10, 5) and (16, 8), so it rises 3 kg in 6 weeks, half a kilogram a week, and its height at each weighed week can be read off. The gap is the dot’s mass minus the line’s:
| week | kg | line | gap |
|---|---|---|---|
| 8 | 4.3 | 4 | +0.3 |
| 9 | 4.4 | 4.5 | -0.1 |
| 10 | 5.2 | 5 | +0.2 |
| 11 | 5.3 | 5.5 | -0.2 |
| 12 | 6.2 | 6 | +0.2 |
| 13 | 6.4 | 6.5 | -0.1 |
| 14 | 6.8 | 7 | -0.2 |
| 15 | 7.7 | 7.5 | +0.2 |
| 16 | 7.9 | 8 | -0.1 |
| 18 | 9.2 | 9 | +0.2 |
Now the four checks. The line rises with the band. There are 5 dots above it (weeks 8, 10, 12, 15 and 18) and 5 below. Above and below are mixed along the whole length, so the tilt is right. And no dot is more than 0.3 kg from the line. It is a good line, and it passes through no dot at all, which it was never meant to.
Why not join the end points?
Crickets chirp faster when the air is warmer, and for some kinds the rate rises roughly in a straight-line pattern with temperature. These data are made up to follow that pattern: a cricket’s chirping on twelve evenings, as pairs (temperature in °C, chirps per minute): (14, 76), (15, 72), (16, 85), (17, 87), (18, 98), (19, 104), (20, 108), (21, 120), (22, 123), (23, 131), (24, 140) and (26, 146).
Line A joins the coolest evening’s dot to the warmest’s. Line B was drawn by eye through (15, 75) and (25, 145). Which is the better fit?
Line A passes through two dots, which can look like a strength. Look at the other ten. Every dot from 15 to 20 °C lies below A, and every dot from 21 to 24 °C lies above it. The count, 4 above against 6 below, is not far off, but the mixing check fails badly: the dots below crowd the cool end and the dots above crowd the warm end. A is too flat. The cause is the two end dots: the one at 14 °C sits well above where the other cool dots point, and the one at 26 °C sits below where the band is heading.
Line B rises 70 chirps over 10 degrees, 7 chirps per minute for each degree. It has six dots above it (at 14, 16, 18, 19, 21 and 24 °C), five below (at 15, 17, 20, 22 and 26 °C), and passes through one, (23, 131). Above and below are mixed all along it. Its largest miss is the coolest evening, 8 chirps above the line: the same dot that dragged A off course.
B is the better fit. Handing the two end dots the job of fixing the line lets two dots outvote ten.
Two lines that both balance
A small drone was flown eight times, each time carrying a different load, until its battery ran out (made-up data). Each pair is (load in grams, flight time in seconds): (30, 267), (40, 250), (45, 251), (55, 230), (60, 231), (70, 212), (80, 206) and (90, 189). Line P passes through (50, 240) and falls 12 seconds for every 10 g. Line Q passes through (30, 270) and (80, 200), falling 14 seconds for every 10 g. Which fits better?
Read each line’s value at the eight loads and subtract it from the flight time:
| g | s | line P | gap | line Q | gap |
|---|---|---|---|---|---|
| 30 | 267 | 264 | +3 | 270 | -3 |
| 40 | 250 | 252 | -2 | 256 | -6 |
| 45 | 251 | 246 | +5 | 249 | +2 |
| 55 | 230 | 234 | -4 | 235 | -5 |
| 60 | 231 | 228 | +3 | 228 | +3 |
| 70 | 212 | 216 | -4 | 214 | -2 |
| 80 | 206 | 204 | +2 | 200 | +6 |
| 90 | 189 | 192 | -3 | 186 | +3 |
Counting does not separate them: each line has 4 dots above and 4 below, mixed along its length. So compare the sizes of the gaps. For P,
and for Q,
P fits a little better: its total is smaller, and its largest miss is 5 seconds against 6. Q’s two largest misses point at its tilt: at 40 g the dot is 6 seconds below Q, and at 80 g it is 6 seconds above. Q runs high on the left and low on the right, which is what a falling line a shade too steep does.
The difference is small, and either line would serve. (With their signs, P’s gaps give 3 - 2 + 5 - 4 + 3 - 4 + 2 - 3 = 0, which says nothing about closeness.) Adding the sizes is a fair way to compare two lines by eye, but it is not how “best” is finally defined: the standard measure squares each gap first, as Least squares regression explains.
The equation of the puppy’s line, and a prediction
Write the equation of the line drawn in Example 1, with M the mass in kilograms and w the age in weeks. Then estimate the puppy’s mass in week 17, the week it was not weighed.
SolutionThe rings in the figure mark (10, 5) and (16, 8) on the line. The slope is
Put (10, 5) into M = 0.5w + b: 5 = 0.5 \times 10 + b = 5 + b, so b = 0. The line is
Check with the other point: 0.5 \times 16 = 8.
These are points of the line, not dots. The dots at those weeks are (10, 5.2) and (16, 7.9), and the line through them has slope \displaystyle \frac{7.9 - 5.2}{16 - 10} = \frac{2.7}{6} = 0.45: a different line, tilted by the scatter of just two dots. In context, the slope says the puppy gained about half a kilogram a week over these weeks, the kind of reading interpreting slope and intercept develops.
For week 17: M = 0.5 \times 17 = 8.5, so about 8.5 kg. Week 17 lies inside the weeks measured, 8 to 18, so this is interpolation, and it sits sensibly between the 7.9 kg of week 16 and the 9.2 kg of week 18.
Predicting in both directions
Use line B from Example 2, with t the temperature in °C and c the chirps per minute.
(a) Write its equation. (b) Predict the chirping rate at 18.5 °C. (c) Kerensa counts a cricket chirping 120 times a minute. Estimate the temperature. (d) What does the line give at 0 °C?
Solution(a) B passes through (15, 75) and (25, 145), so its slope is \displaystyle \frac{145 - 75}{25 - 15} = \frac{70}{10} = 7. Put (15, 75) into c = 7t + b: 75 = 105 + b, so b = -30, and
Check: 7 \times 25 - 30 = 145. The slope says that each degree warmer goes with about 7 more chirps a minute.
(b) c = 7 \times 18.5 - 30 = 129.5 - 30 = 99.5, about 100 chirps per minute. The evenings ran from 14 to 26 °C, so this is interpolation.
(c) Now the chirping rate is known and the temperature is not, so put c = 120 in and solve:
About 21 °C, inside the temperatures measured. One caution: B was drawn to keep the vertical gaps (chirps) small. A line drawn to predict temperature from chirps would keep the gaps in temperature small instead and come out slightly different, so a reading in this direction is a fair estimate, not the best one.
(d) c = 7 \times 0 - 30 = -30. A cricket cannot chirp a negative number of times. 0 °C is far below the coolest evening measured, 14 °C, so this is extrapolation, and here it gives nonsense.
How far can the drone’s line be pushed?
Use line P from Example 3, with T the flight time in seconds and p the load in grams. The rings in the figure mark (50, 240) and (100, 180) on it.
(a) Write its equation. (b) Predict the flight time with a 65 g load. (c) What does the line predict for a 150 g load? (d) At what load does the line predict a flight time of 0?
Solution(a) The slope is \displaystyle \frac{180 - 240}{100 - 50} = \frac{-60}{50} = -1.2. Put (50, 240) into T = -1.2p + b: 240 = -60 + b, so b = 300, and
Check: 300 - 1.2 \times 100 = 180. Each extra gram of load goes with about 1.2 seconds less in the air.
(b) T = 300 - 1.2 \times 65 = 300 - 78 = 222 seconds, which is 3 minutes 42 seconds. The loads tested ran from 30 to 90 g, so this is interpolation.
(c) T = 300 - 1.2 \times 150 = 300 - 180 = 120 seconds. The arithmetic is fine, but 150 g is far outside 30 to 90. Nothing in the data says the straight pattern lasts that far, or even that the drone can lift 150 g. This is extrapolation and should not be trusted.
(d) Set T = 0: 300 - 1.2p = 0, so 1.2p = 300 and p = 250. Past 250 g the line gives negative flight times, which are impossible, so somewhere beyond the data the line must stop describing this drone. The data stop at 90 g and cannot say where.
Boundaries
The pattern has to be straight. On dots that bend, as in Exercise 8, any straight line is too high in one stretch and too low in another. On dots with no trend, a line describes nothing.
It predicts the trend, not a single case. Line P predicts 222 seconds for a 65 g load, but the test flights landed up to 5 seconds away from it, so a real flight with that load could too.
Inside the data, with care; outside, with doubt. Extrapolation assumes the pattern continues where nothing was measured, and far enough out it can give impossible answers: a negative number of chirps, a negative flight time.
A dot far from the rest pulls on the eye. One unusual dot can tip a line drawn by eye, as the end dot did to line A. How much a single point can move a line is the subject of Outliers, leverage and influential points.
Moving together is not causing. A line says how two variables went together in the data. It does not say that changing one would change the other; Correlation is not causation: lurking and confounding variables shows why.
Where this goes next
The vertical gaps of this lesson get a name, Residuals, and their pattern becomes a test of whether a line was the right choice at all. Squaring each gap and adding the squares gives the standard measure of fit, and the one line that makes that total smallest is the least squares line, or regression line, built in Least squares regression; in practice a calculator finds it, which is Fitting linear and exponential models with technology. Reading what its slope and intercept say is interpreting the slope and intercept, predicting with that exact line returns to extrapolation, and how tightly the dots hug a line gets a single number in Correlation.
Exercises
Exercises 1 to 8 go with Part 1 of the lesson (Examples 1 to 3), Exercises 9 to 14 with Part 2 (Examples 4 to 6), and the reasoning group draws on both.
Part 1: judging a line
Lysander measured his sunflower’s height every five days (made-up data). Each pair is (day, height in centimeters): (20, 33), (25, 42), (30, 62), (35, 73), (40, 88), (45, 108), (50, 117), (55, 138) and (60, 148). Line R passes through (20, 30) and (60, 150), rising 3 cm a day. Line S passes through (20, 40) and (60, 140), rising 2.5 cm a day.
- How many dots lie above line R, and how many below?
- How many dots lie above line S, and how many below? Where along S do the dots above it sit?
- Find the vertical gap from each dot to R and to S. Add the sizes of the gaps for each line, and say which line fits better.
Kerensa recorded a cricket’s chirping on five evenings (made-up data), and two classmates drew lines J and K through her scatter plot. The table gives the data and each line’s value at each temperature.
| °C | chirps | line J | line K |
|---|---|---|---|
| 16 | 83 | 82 | 82 |
| 18 | 95 | 96 | 94 |
| 20 | 112 | 110 | 106 |
| 22 | 121 | 124 | 118 |
| 24 | 139 | 138 | 130 |
- Find each line’s gap at each temperature, as chirps minus line. For each line, count the dots above and below and add the sizes of the gaps. Which line fits better?
Jaya weighed her puppy once a week (made-up data). Each pair is (week, kilograms): (9, 3.1), (10, 3.8), (11, 4.2), (12, 4.9), (13, 5.2), (14, 6.0), (15, 6.3), (16, 7.1) and (17, 7.4).
- Isidore draws a line for Jaya’s puppy through (10, 4) and (16, 7). How many dots lie above it, below it and on it? Is it a good line, and if not, how should it move?
- Lysander says a line of best fit has to pass through at least two of the dots, or it has not really been fitted to the data. Is he right?
- Henrietta-Jo’s scatter plot rises from left to right. Her line has six dots above it and six below, but the six above are all on the left half of the plot and the six below are all on the right half. What is wrong with the line, and which way should she turn it?
- Later in the summer Kerensa measured her own sunflower every ten days (made-up data): (60, 150), (70, 168), (80, 178), (90, 183) and (100, 185), in days and centimeters. How much did it grow in each ten-day gap? Should a straight line be fitted to these five dots?
Part 2: equations and predictions
- Write the equation of line R from the sunflower plot, with h the height in centimeters and d the day.
- Use line R to predict the sunflower’s height on day 42 and on day 33. Is each prediction interpolation or extrapolation?
- A better line for Jaya’s puppy passes through (8, 2.8) and (18, 7.8). Write its equation, with M the mass in kilograms and w the week. Predict the mass at week 20, and say whether that is interpolation or extrapolation.
- A second drone was tested with loads between 25 and 85 g. Its line of best fit for flight time T seconds against load p grams passes through (20, 290) and (80, 230). Write its equation, predict the flight time for a 45 g load, and find the load at which the line predicts a time of 0. What does that say about the line?
- A line of best fit for a sunflower measured from day 15 to day 50 is h = 2.8d - 20. Predict its height on day 30, day 80 and day 5, and say which predictions are interpolation.
- Henrietta-Jo writes an equation for Lysander’s sunflower using two of the dots, (25, 42) and (55, 138). What equation does she get, and why is it not line R?
Reasoning
- Suppose Kerensa had stopped measuring her sunflower of Exercise 8 at day 80. A line through (60, 152) and (80, 180) fits her first three dots closely. What does it predict for day 75 and for day 100? Compare with what she measured, and explain why interpolation deserves more trust than extrapolation.
- Gisli and Jaya each draw a line by eye for the drone of Example 3. For a 65 g load, Gisli’s line predicts 222 seconds and Jaya’s predicts 226 seconds. Is one of them wrong?
Answers
- 4 above (days 20, 30, 45 and 55) and 5 below (days 25, 35, 40, 50 and 60).
- 4 above (days 45, 50, 55 and 60) and 5 below (days 20 to 40). The dots above all sit at the right end and the dots below at the left end, so S is too flat.
- R fits better. The gaps from R are +3, -3, +2, -2, -2, +3, -3, +3, -2, with sizes adding to 23 cm. The gaps from S are -7, -10.5, -3, -4.5, -2, +5.5, +2, +10.5, +8, with sizes adding to 53 cm.
- J fits better. Its gaps are +1, -1, +2, -3, +1: 3 above, 2 below, sizes adding to 8. The gaps from K are +1, +1, +6, +3, +9: all 5 above, sizes adding to 20. K is too low and too flat.
- 1 above (week 16), 7 below and 1 on (week 14), from M = 0.5w - 1. Its tilt follows the band, but it sits too high: slide it down by about 0.2 kg without turning it.
- No. A line of best fit runs through the middle of the band and need not pass through any dot; the line in Example 1 passes through none and fits well.
- The line is too steep. Dots above it on the left mean it is too low there, and dots below it on the right mean it is too high there. She should turn it flatter about its middle until the dots above and below are mixed along its length.
- It grew 18, 10, 5 and 2 cm in the four gaps. The growth shrinks every time, so the dots bend over and level off, and a straight line would be too low in the middle and too high at both ends. No straight line fits them.
- h = 3d - 30. The slope is \displaystyle \frac{150 - 30}{60 - 20} = \frac{120}{40} = 3, and 30 = 3 \times 20 + b gives b = -30.
- 96 cm on day 42 (3 \times 42 - 30) and 69 cm on day 33 (3 \times 33 - 30). Both days lie inside 20 to 60, so both are interpolation.
- M = 0.5w - 1.2, and about 8.8 kg at week 20. The slope is \displaystyle \frac{7.8 - 2.8}{18 - 8} = 0.5 and 2.8 = 4 + b gives b = -1.2; then 0.5 \times 20 - 1.2 = 8.8. The data run from week 9 to week 17, so this is extrapolation: a short step, so likely close, but not backed by any dot.
- T = 310 - p; 265 seconds for 45 g; a time of 0 at p = 310 g. The slope is \displaystyle \frac{230 - 290}{80 - 20} = -1 and 290 = -20 + b gives b = 310. But 310 g is far outside 25 to 85 g, and past it the line gives negative times: the line describes only the loads tested, and cannot say how this drone behaves far beyond them.
- Day 30: 64 cm, interpolation. Day 80: 204 cm, extrapolation. Day 5: -6 cm, extrapolation, and impossible. Each is 2.8d - 20, and only day 30 lies inside 15 to 50.
- h = 3.2d - 38. The slope is \displaystyle \frac{138 - 42}{55 - 25} = \frac{96}{30} = 3.2 and 42 = 80 + b gives b = -38. Her two dots are not on line R: (25, 42) is 3 cm below it and (55, 138) is 3 cm above it, so the line through them is steeper.
- The line is h = 1.4d + 68 (slope \displaystyle \frac{180 - 152}{80 - 60} = 1.4). Day 75: 173 cm, between the 168 cm of day 70 and the 178 cm of day 80, as expected. Day 100: 208 cm, against a measured 185 cm, 23 cm too tall. Day 75 had measured dots on both sides to hold the prediction in place; day 100 had none, and the line could not know the growth would slow.
- Not necessarily. Two careful lines by eye usually differ a little. A difference of 4 seconds is smaller than the 5 seconds by which real flights sat off line P, so both predictions are reasonable; it is fair to say “about 222 to 226 seconds”.