MathemagiciansLibraryExplorationsDeep Dives
← Mathematics · Upper Secondary
MathematicsUpper Secondary

Lines of best fit — drawing and using them

U4 — Statistics Advancing › U4.3 — Correlation and RegressionLecture 2 of 4~2900 words

The data point that gives the wrong prediction

Go back to the twelve students from the last lecture, with their hours of revision and their scores. A new student, Amara, plans to revise for 7 hours. What score would you predict for her?

One student in the data revised for exactly 7 hours, and that student scored 50%. So the obvious answer is 50%.

It is not the best answer. The student who revised for 6 hours scored 55%. So the 7-hour student scored less than someone who revised less. That one score carries its own story: perhaps a bad night's sleep, or a hard question. A prediction built on one student copies that student's luck.

A better prediction uses all twelve students at once. For that, you need one line that stands for the whole pattern. This lecture shows you how to draw it, the one point it must pass through, and when to trust it.

One line for the whole pattern

A line of best fit is a straight line drawn on a scatter graph to show the overall trend of the points. It does not join the dots. Joining them would give a zigzag that copies every student's luck. The line ignores the zigzag and keeps the trend.

0 2 4 6 8 10 12 14 16 18 0 20 40 60 80 100 Hours of revision Exam score (%) mean point (8, 58.7) ≈ 55
The line passes through the mean point (8, 58.7), with points above and below it. The dashed guide rises from 7 hours. It passes the student who scored 50% and meets the line at about 55%.

Read the line at 7 hours. It gives about 55%, so that is the prediction for Amara. It is higher than 50% because the line uses all twelve students, not one.

The line is straight because a correlation is a straight-line pattern. So draw a line of best fit only when the scatter graph shows a linear correlation. If the correlation is strong, its predictions are close. If it is weak, they are rough. If there is no correlation, or the points follow a clear curve, do not draw one.

But many straight lines could pass through the cloud. Two ideas decide which one is best. The first fixes a point that the line must pass through. The second fixes its gradient.

The mean point: where the line must pass

Find the mean of the twelve hours, and the mean of the twelve scores.

The symbol is read "x bar". It means the mean of the x-values, and means the mean of the y-values. The point is called the mean point. A line of best fit should pass through it.

Why this point? This is the hard part of the lecture. Spend time here.

Start with one list of numbers: 4, 4, 9 and 7. Their mean is 6. Now find how far each number is from the mean: −2, −2, +3 and +1. Add them. The total is 0. This is true for any list, because the mean is the total shared out equally. So the amounts above the mean exactly fill the amounts below it. The mean is the balance point of the list.

Now use pairs. Take four points: (1, 4), (2, 4), (4, 9) and (5, 7). The mean of the x-values is 3, and the mean of the y-values is 6. So the mean point is (3, 6). Draw any line through (3, 6), for example . For each point, measure the vertical gap: the point's y-value minus the line's y-value at the same x.

0 1 2 3 4 5 6 0 2 4 6 8 10 x y +1 −0.5 +1.5 −2 (3, 6)
The line passes through the mean point (3, 6). Gaps above the line are positive, and gaps below are negative.

The gaps are +1, −0.5, +1.5 and −2. Their total is 0. Now try a different gradient through the same point: . The gaps become 0, −1, +2 and −1. The total is 0 again.

Here is why. Each gap has two parts: how far the point is above , minus how far the line is above at that x. The first parts add to zero, because is the balance point of the y-values. The second parts are the gradient multiplied by each point's distance from . Those distances add to zero, because is the balance point of the x-values. Zero minus zero is zero.

That is it. That is the whole idea. Every line through the mean point balances: the gaps above it cancel the gaps below it, whatever its gradient. A line that misses the mean point cannot balance. Raise to , and every gap shrinks by 1. The total becomes −4: the line is too high.

The mean point

The mean point is : the mean of the x-values and the mean of the y-values.

For any line through it, the gaps above the line exactly balance the gaps below. So a line of best fit passes through the mean point.

Choosing the gradient

The mean point fixes where the line passes, not how steep it is. So the eye has one more job. Try it below.

Explore — turn the line about the mean point

Change the gradient with the slider or the − / + buttons. The line always turns about the mean point. Watch the gap totals, then watch the two halves. Then move the line up or down, away from the mean point.

Presets:

Gradient: 3.4

Move up or down: 0 percentage points

The figure shows a line through the mean point with gradient 1. The table compares lines with different gradients. The first three pass through the mean point; the last is moved up by 5 percentage points.

0 2 4 6 8 10 12 14 16 18 0 20 40 60 80 100 Hours of revision Exam score (%)
Gradient 1, through the mean point. The gaps balance in total, but the left half is below the line and the right half is above it.
LineAbove, belowGap aboveGap belowLeft half above, belowRight half above, below
Gradient 16, 650500, 66, 0
Gradient 3.45, 715.915.93, 32, 4
Gradient 66, 661615, 11, 5
Gradient 3.4, moved up 50, 120600, 60, 6

Through the mean point, the two gap totals were equal at every gradient. As soon as the line left the mean point, the balance broke.

But balance in total is not enough. At gradient 1, all six students on the left were below the line and all six on the right were above it. The left side simply cancelled the right side. At gradient 6, the same happened the other way round. Near 3.4, the points above and below were mixed along the whole line. That is the second rule: points above and below should be spread along the line, not gathered at its two ends.

Here is a check that does not depend on your eye. Split the points into a left half and a right half. Find the mean point of each half, and join the two. For the revision data, the halves have mean points (4.5, 46.8) and (11.5, 70.5).

The halves have equal numbers of points, so (8, 58.7) lies exactly halfway between the two half-means: this line passes through the mean point too. Some textbooks call this the method of semi-averages.

Drawing a line of best fit

1. Check that the scatter graph shows a straight-line correlation. Name any outlier. You may leave it out of the line, if you say so and why.

2. Calculate the mean point and plot it.

3. Place your ruler through the mean point. Turn it until the points above and below are mixed along the whole line, with roughly equal numbers on each side.

4. Draw one straight line across the range of the data.

Stop and think

Kenji draws his line from the first student (2, 38) to the last student (16, 84). Is that a line of best fit?

Show the answer

No. It uses two students and ignores the other ten, so it copies the luck of those two. Kenji's line gives 57.7 at 8 hours, missing the mean point by about 1. That is close only by chance. With a different first or last student, it could miss badly.

Using the line: inside the data and outside it

A café recorded the midday temperature and the number of ice creams it sold on 10 days (invented data).

Temperature (°C)11131416182123252732
Ice creams sold7987114114152172209218256299

The mean point is (200 ÷ 10, 1700 ÷ 10) = (20, 170). The line below passes through it, with five days above and five below.

0 5 10 15 20 25 30 35 0 50 100 150 200 250 300 350 Midday temperature (°C) Ice creams sold ≈ 192 22
The line of best fit passes through the mean point (20, 170). At 22 °C it gives about 192 ice creams.

To estimate the sales on a 22 °C day, go up from 22 to the line, then across. The line gives about 192 ice creams.

No day was exactly 22 °C, but there are days on both sides of it. Estimating a value inside the range of the data is called interpolation. When the correlation is strong, it is a reasonable estimate.

Now suppose a heatwave brings a 45 °C day. Extend the line and read it.

0 10 20 30 40 50 −100 0 100 200 300 400 500 Midday temperature (°C) Ice creams sold (45, 445)? (0, −50)? the data
The shaded band is the range of the data, 11 °C to 32 °C. The dashed parts of the line are extrapolation.

The extended line gives about 445 ice creams. But the hottest day in the data was 32 °C, so above that there is no evidence. Perhaps people stay indoors in such heat. Perhaps the café cannot make 445 in a day. Estimating a value outside the range of the data is called extrapolation, and it is unreliable.

The other end shows the danger clearly. At 0 °C, the line gives −50 ice creams, which is impossible. The line was built from days between 11 °C and 32 °C, and it knows nothing outside them.

The equation of the line, and what it says

The last lecture promised that a line through the points would measure the steepness of the trend. Here it is. Read two points from the drawn ice cream line, far apart: (12, 82) and (28, 258).

Substitute (12, 82) into : , so . The equation is . Check with the mean point: . Correct.

Now read it in the words of the problem. The gradient is 11 ice creams per °C: for each extra degree, the café tends to sell about 11 more. This is the steepness of the trend, with its units. The intercept, −50, is the value at 0 °C, which is outside the data. So it has no real meaning. It only places the line. Before you read meaning into an intercept, ask whether x = 0 is inside the data.

One step in this method causes most mistakes. Find it below.

Spot the error — the equation of the ice cream line

A student found the equation of the ice cream line. One line of the working is wrong. Tap it.

A student's working for the equation of the ice cream line, with the wrong step named.

  1. Two points are needed. Choose them far apart, so that small reading errors matter less.
  2. Wrong: Use the first and last days in the table, (11, 79) and (32, 299). These are data points, not points on the drawn line. The first day is 8 above the line, and the last day is 3 below it.
  3. Gradient = (299 − 79) ÷ (32 − 11) = 220 ÷ 21 ≈ 10.5.
  4. Substitute (11, 79): 79 = (220 ÷ 21) × 11 + c, so c ≈ −36.2.
  5. Equation: y ≈ 10.5x − 36.2. The correct equation, from points on the drawn line, is y = 11x − 50.

The mistake is natural, because the data points are the clearest marks on the page. But the line stands for all the points, so its equation must come from the line itself.

Stop and think

The revision line is . Its intercept says that a student who revises for 0 hours scores about 31.5%. Can you trust this?

Show the answer

Not much. The data runs from 2 to 16 hours, so 0 hours is an extrapolation. Try 30 hours: , a score of 133.5%, which is impossible. The gradient is more useful: each extra hour tends to go with about 3.4 more percentage points, for students in this range.

Worked examples

Worked Example 1 — Drawing the line through the mean point

Eight students recorded the distance from home to school and the time of their journey (invented data).

Distance (km)124568913
Time (min)1513232331333947

Find the mean point, and check that the line is a good line of best fit.

The distances add to 48, so . The times add to 224, so . The mean point is (6, 28).

Does the line pass through it? . Yes.

Now the gaps. The line gives 13, 16, 22, 25, 28, 34, 37 and 49, so the gaps are +2, −3, +1, −2, +3, −1, +2 and −2. Each half has two points above and two below.

Answer: the line passes through the mean point, and the points above and below are mixed along its whole length. It is a good line of best fit.

Check: the gaps add to 0, as they must through the mean point.

Worked Example 2 — Reading the line both ways

Use from Worked Example 1. (a) Estimate the time for a 7 km journey. (b) Estimate the distance for a 40-minute journey. (c) Are these reliable, and what do the gradient and intercept mean?

(a) . The estimated journey is about 31 minutes.

(b) Now y is known. Solve : , so , about 10 km. On a graph, go across from 40 to the line, then down.

(c) Both are interpolations: 7 km and 10 km are inside the data (1 to 13 km), and the points lie close to the line. So both are reasonable. The gradient says each extra kilometre tends to add about 3 minutes. The intercept, 10 minutes for 0 km, is outside the data, so do not claim it measures anything.

Check: the students at 6 km and 8 km took 31 and 33 minutes, so 31 minutes for 7 km fits the data.

Worked Example 3 — When a straight line stops being honest

The last lecture gave the values of 10 cars of one model, aged 1 to 10 years, as a percentage of their price when new: 85, 74, 66, 60, 52, 47, 41, 37, 33 and 30. A dealer draws the line . (a) Check that it passes through the mean point. (b) Use it to predict the value at 12 years and at 15 years. (c) Comment.

(a) The mean age is 5.5 and the mean value is 525 ÷ 10 = 52.5. The line gives . Yes.

(b) At 12 years: , so about 13.5%. At 15 years: , so −4.5%.

(c) Both are extrapolations, and the second is impossible. There is a deeper problem. These points bend: the value falls fast at first, then slowly. The first and last cars are above the line (by 85 − 79.5 = 5.5 and 30 − 25.5 = 4.5), and the middle cars are below it. So a straight line is a weak model here, even inside the data. Beyond 10 years the real values flatten, while the line keeps falling.

Trap 1 — Joining the dots, or forcing the line

Do not join the points, and do not force the line through the origin or through the first and last points. Draw one straight line through the mean point, with points above and below mixed along its length.

Trap 2 — Using data points for the equation

To find the gradient and the intercept, read two points from the drawn line, far apart. Data points have their own zigzag, so an equation through two of them is not the equation of the line of best fit.

Trap 3 — Trusting an extrapolation

A value outside the range of the data, including an intercept when x = 0 is outside it, is an extrapolation. Give the number if asked, and say why it is unreliable.

Try it yourself

Work each one on paper first. Open a hint only when you are stuck.

  1. A park recorded the hours of sunshine and the number of visitors (in hundreds) on 8 days.

    Sunshine (hours)23456789
    Visitors (hundreds)1413191821252327

    Three students suggest lines of best fit: A: , B: , C: . Which is the best line? Explain.

    Hint 1

    Find the mean point first. Which lines pass through it?

    Hint 2

    For the lines through the mean point, find where the points lie: above or below, on the left and on the right.

    Full answer

    The hours add to 44, so . The visitors add to 160, so . The mean point is (5.5, 20). Line A gives , so it misses the mean point. It is too high: five points are below it and only two are above. Line B gives 20 and line C gives , so both pass through the mean point. Line C is too shallow: all four days on the left (2 to 5 hours) are below it and all four on the right are above it. Line B has gaps +1, −2, +2, −1, 0, +2, −2, 0: above and below are mixed on both sides. So B is the best line. Check: B's gaps add to 0, as they must through the mean point.

  2. A student measured the height of a plant every few days, from day 2 to day 20. The line of best fit is , where x is the day and y is the height in cm. (a) Estimate the height on day 10. (b) On which day does the line give a height of 25 cm? (c) Estimate the height on day 60, and comment. (d) What does the gradient mean?

    Hint 1

    For (a) and (c), substitute x. For (b), y is given, so solve for x.

    Hint 2

    For (c), is day 60 inside the days that were measured? What happens to real plants as they grow older?

    Full answer

    (a) , so about 19 cm. This is interpolation, so it is reasonable. (b) , so and : day 14. (c) , so 94 cm. Day 60 is far outside the data (days 2 to 20), so this is an extrapolation and unreliable. Many plants slow down or stop growing, so the real height could be much less. (d) The plant tends to grow about 1.5 cm per day during the days measured. Check (b): .

  3. A driver recorded the length of 12 journeys, between 40 km and 300 km, and the fuel used. The line of best fit passes through (50, 4.5) and (250, 16.5), where x is in km and y in litres. (a) Find the equation of the line. (b) Explain the gradient in context. (c) What does the intercept mean, and can you trust it? (d) Estimate the fuel for a 180 km journey.

    Hint 1

    Gradient = change in y ÷ change in x. Then substitute one of the points into y = mx + c.

    Hint 2

    The gradient is in litres per km. How much is that per 100 km?

    Full answer

    (a) Gradient = (16.5 − 4.5) ÷ (250 − 50) = 12 ÷ 200 = 0.06. Then , so . The equation is . (b) Each extra kilometre tends to use about 0.06 litres more fuel, which is about 6 litres per 100 km. (c) The intercept says that a journey of 0 km uses 1.5 litres. A possible story is fuel used while starting and waiting. But 0 km is outside the data (40 to 300 km), so it is an extrapolation: do not trust it as a measurement. (d) , so about 12.3 litres. Check: (250, 16.5) gives .

  4. Five learners recorded how many weeks they had practised typing (x) and their speed in words per minute (y). One speed was lost.

    Weeks48121620
    Speed (words per minute)304755k82

    The teacher had drawn the line of best fit through the mean point. (a) Find k. (b) Check the line by finding the gaps. (c) Predict the speed after 25 weeks, and comment.

    Hint 1

    The line passes through . You can find from the table. What does the line give at ?

    Hint 2

    If is known, then the five speeds must add to .

    Full answer

    (a) The weeks add to 60, so . The line passes through the mean point, so . The five speeds must add to . The four known speeds add to , so . (b) The line gives 32, 44, 56, 68 and 80. The gaps are −2, +3, −1, −2 and +2. They add to 0, and the points above and below are mixed. (c) words per minute. But 25 weeks is outside the data (4 to 20 weeks), so this is an extrapolation. Typing speed tends to level off with practice, so 95 may be too high. Check: (16, 66) is 2 below the line, close to the trend, so k = 66 is believable.

The bigger idea

In 2004, four scientists published a short paper in the journal Nature. They fitted a straight line to the winning times of the Olympic 100-metre sprint, one line for men and one for women. The women's times had been falling faster, so the two lines, extended into the future, crossed just before the 2156 Olympics, at about 8.08 seconds. The paper said this would happen only if the trends continued. Many readers argued about it as if it were a forecast. Follow the lines far enough, and they give a race finished in zero seconds.

Mark Twain made the same point as a joke in 1883. The lower Mississippi River had become 242 miles shorter in 176 years. Extending the trend, he concluded that in 742 years the river would be under two miles long.

A line of best fit is a model: the simplest honest summary of a cloud of points. Inside its data it is very useful. Outside, it is a guess drawn with a ruler. The next lecture gives a number for how closely the points follow a line, and a later one calculates the line exactly.

Key concepts in this lesson