Line of Best Fit

Through the middle of the drift.

No line passes through every dot

An ice cream stand in a park records, on five days, the hours of sunshine and the number of ice creams it sold, in hundreds. Write x for the hours of sunshine and y for the ice creams sold. The five days give the points (1, 3), (3, 3), (5, 6), (7, 6) and (9, 9).

The dots trend upward: sunnier days tended to sell more ice creams. But they do not lie on one straight line, so no line passes through all of them. A line of best fit is the single straight line that follows the trend through the middle of the dots. It summarizes all five days at once, and it can be used to make estimates.

xy

The five days: the dots trend upward, but no straight line passes through them all.

The mean point

Start with the center of the dots. The mean of the x-values is (1 + 3 + 5 + 7 + 9) ÷ 5 = 25 ÷ 5 = 5 hours, and the mean of the y-values is (3 + 3 + 6 + 6 + 9) ÷ 5 = 27 ÷ 5 = 5.4 hundred ice creams. The point (5, 5.4) is the mean point.

The mean point is the balance point of the dots, across and up. A line through the middle of the dots has to pass through their center, so every line of best fit is drawn through the mean point.

xymean

The mean point, (5, 5.4), sits in the middle of the five dots.

Drawing the line through the mean point

Put a ruler through the mean point and turn it until it follows the trend of the dots, with roughly as many dots above the line as below it. Here the line y = 0.6x + 2.4 passes through the mean point, since 0.6 × 5 + 2.4 = 5.4. Two dots, (5, 6) and (9, 9), lie above it, two, (3, 3) and (7, 6), lie below it, and (1, 3) lies on it.

Balance is not only a count. The dots above the line should not all be at one end. The flat line y = 5.4 also passes through the mean point, but the two dots on the left are both below it and the other three are all above it. That line cuts across the trend instead of following it.

A line drawn this way is drawn by eye, so two people may draw slightly different lines. Both are acceptable if they pass through the mean point and follow the trend.

xymean

The line y = 0.6x + 2.4 passes through the mean point, with two dots above it, two below it and one on it.

xymean

The flat line y = 5.4 also passes through the mean point, but the dots on the left are all below it and the dots on the right are above it, so it does not follow the trend.

Reading an estimate from the line

To estimate the sales on a day with 6 hours of sunshine, start at x = 6 on the horizontal axis, go up to the line, and then across to the vertical axis. The line is at y = 6 there, so the estimate is about 6 hundred, or 600, ice creams.

The estimate comes from the line, which uses all five days, not from the nearest dot. No day had exactly 6 hours of sunshine, and the line fills that gap.

xymean

Up from x = 6 to the line, then across: the line gives y = 6.

The equation of the line

A drawn line can be written as an equation y = mx + c. Choose two points on the line that are far apart, so that the reading is accurate. The line passes through the mean point, (5, 5.4), and through (10, 8.4). Its gradient is (8.4 − 5.4) ÷ (10 − 5) = 3 ÷ 5 = 0.6. Then 5.4 = 0.6 × 5 + c = 3 + c, so c = 2.4, and the line is y = 0.6x + 2.4.

Putting x = 6 into the equation gives y = 0.6 × 6 + 2.4 = 3.6 + 2.4 = 6, the same estimate as reading the graph. The equation is quicker and more exact, and it can be used for values that are hard to read off the grid.

The gradient in context

The gradient is a rate. It is the change in y for an increase of 1 in x, so its units are the units of y per unit of x. Here it is 0.6 hundred ice creams per hour of sunshine: each extra hour of sunshine goes with about 60 more ice creams sold.

Say it in the words of the data, with the units: “For each extra hour of sunshine, the stand sells about 60 more ice creams.” A negative gradient is read the same way, as a decrease: a gradient of −2 degrees per hour means the temperature falls by about 2 degrees each hour.

The intercept, c = 2.4, is the value the line gives at x = 0: about 240 ice creams on a day with no sunshine at all. Treat it with care. The data run from 1 hour to 9 hours of sunshine, and x = 0 lies outside them, so the line is being read where nothing was measured. Reading a line outside the data is the subject of a later lesson, Interpolation and Extrapolation.

Worked example: Oven Temperature Against Baking Time, with the Line of Best Fit Read Backwards

Question A baker baked one loaf at eight oven temperatures and recorded the time it needed. The pairs of (temperature in Celsius, time in minutes) were (180, 50), (190, 44), (200, 43), (210, 43), (220, 39), (230, 40), (240, 34) and (250, 35). The line of best fit has gradient −0.2. (a) Find the mean point and the equation of the line, and say what the gradient means. (b) The baker wants the loaf to take 40 minutes. Find the oven temperature the line suggests.

  1. 1.Find the mean temperature. The temperatures total 180 + 190 + 200 + 210 + 220 + 230 + 240 + 250 = 1720, so the mean is 1720 ÷ 8 = 215 Celsius.

    3035404550180200220240260time, minutesoven temperature (Celsius)8 loaves: temperature against time
    3035404550180200220240260time, minutesoven temperature (Celsius)8 loaves: temperature against time
    The eight loaves, with the oven temperature across and the time up. The points fall to the right, so the correlation is negative.
  2. 2.Find the mean time. The times total 50 + 44 + 43 + 43 + 39 + 40 + 34 + 35 = 328, so the mean is 328 ÷ 8 = 41 minutes, and the mean point is (215, 41).

    3035404550180200220240260time, minutesoven temperature (Celsius)1720 divided by 8 = 215 C328 divided by 8 = 41 minutes
    3035404550180200220240260time, minutesoven temperature (Celsius)1720 divided by 8 = 215 C328 divided by 8 = 41 minutes
    The cross is the mean point, (215, 41).
  3. 3.The line passes through the mean point with gradient −0.2, so 41 = −0.2 × 215 + c, that is 41 = −43 + c, which gives c = 84.

    3035404550180200220240260time, minutesoven temperature (Celsius)41 = -0.2 × 215 + c, so c = 84
    3035404550180200220240260time, minutesoven temperature (Celsius)41 = -0.2 × 215 + c, so c = 84
    The line of gradient −0.2 through the mean point has 41 = −43 + c, so c = 84.
  4. 4.(a) The line of best fit is m = 84 − 0.2x, where x is the temperature in Celsius and m is the time in minutes. The gradient −0.2 is −0.2 minutes for each degree, so every 10 Celsius hotter takes about 2 minutes off the baking time.

    3035404550180200220240260time, minutesoven temperature (Celsius)20 C4m = 84 - 0.2x20 C hotter takes 4 minutes off
    3035404550180200220240260time, minutesoven temperature (Celsius)20 C4m = 84 - 0.2x20 C hotter takes 4 minutes off
    (a) The line is m = 84 − 0.2x, and the gradient triangle shows 20 Celsius of extra heat taking 4 minutes off.
  5. 5.(b) Put m = 40 into the equation: 40 = 84 − 0.2x, so 0.2x = 84 − 40 = 44 and x = 44 ÷ 0.2 = 220 Celsius. Check: 84 − 0.2 × 220 = 84 − 44 = 40, and 220 Celsius lies between the 180 and the 250 the baker tested, so the answer is inside the readings.

    3035404550180200220240260time, minutesoven temperature (Celsius)20 C440 = 84 - 0.2x, so 0.2x = 44x = 220 C
    3035404550180200220240260time, minutesoven temperature (Celsius)20 C440 = 84 - 0.2x, so 0.2x = 44x = 220 C
    (b) Reading in at 40 minutes and down to the temperature axis gives 220 Celsius.

Answer: (a) the mean point is (215, 41) and the line of best fit is m = 84 − 0.2x, with gradient −0.2, so every 10 Celsius hotter takes about 2 minutes off; (b) 220 Celsius

Common mistakes

  • Reading across from 40 minutes to the nearest point and answering 230 Celsius. That loaf took 40 minutes on one trial; the line averages all eight trials and puts the temperature at 220 Celsius.
  • Solving 40 = 84 − 0.2x by taking 84 from both sides and then dividing by 0.2 without minding the sign, which gives −220. Move the 0.2x to the left and the 40 to the right instead, so that 0.2x = 44.

More scatter plots and correlation problems, worked step by step →

Worked example: An Aquarium Gift Shop's Takings, and a Day the Shop Closed Early

Question An aquarium recorded, on eight days, the visitors in hundreds and the gift shop takings in hundreds of dollars. The pairs of (visitors, takings) were (1, 12), (2, 17), (3, 18), (4, 25), (5, 23), (6, 28), (7, 31) and (8, 10). On the last of those days a power cut closed the shop at midday. Drawn through all eight days the line of best fit has gradient 1; drawn through the other seven it has gradient 3. (a) Find the equation of each line. (b) Estimate the takings on an ordinary day with 600 visitors from each line, and say which estimate to use.

  1. 1.Plot the eight days. Seven of them climb steadily, while the power cut day, at 8 hundred visitors and only 10 hundred dollars, sits far below the rest: it is the outlier.

    010203002468takings, $ hundredvisitors, hundred8 days, and one power cut day
    010203002468takings, $ hundredvisitors, hundred8 days, and one power cut day
    The eight days. Seven climb steadily; the power cut day, far to the right and low down, is the outlier.
  2. 2.Find the mean point of all eight days. The visitors total 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36, so the mean is 36 ÷ 8 = 4.5 hundred, and the takings total 164, so the mean is 164 ÷ 8 = 20.5 hundred dollars.

    010203002468takings, $ hundredvisitors, hundred36 divided by 8 = 4.5 hundred164 divided by 8 = 20.5 hundred
    010203002468takings, $ hundredvisitors, hundred36 divided by 8 = 4.5 hundred164 divided by 8 = 20.5 hundred
    The cross is the mean point of all eight days, (4.5, 20.5).
  3. 3.The line through all eight days has gradient 1 and passes through (4.5, 20.5), so 20.5 = 1 × 4.5 + c and c = 16.

    010203002468takings, $ hundredvisitors, hundred20.5 = 1 × 4.5 + c, so c = 16
    010203002468takings, $ hundredvisitors, hundred20.5 = 1 × 4.5 + c, so c = 16
    The line of gradient 1 through that mean point has 20.5 = 4.5 + c, so c = 16.
  4. 4.Leave the power cut day out. The other seven have visitors totaling 28, a mean of 4, and takings totaling 154, a mean of 22. That line has gradient 3, so 22 = 3 × 4 + c and c = 10.

    010203002468takings, $ hundredvisitors, hundredwithout it: 28 divided by 7 = 4154 divided by 7 = 22 hundred
    010203002468takings, $ hundredvisitors, hundredwithout it: 28 divided by 7 = 4154 divided by 7 = 22 hundred
    Leaving the power cut day out moves the mean point up and left, to (4, 22).
  5. 5.(a) Through all eight days the line is y = x + 16, and through the seven ordinary days it is y = 3x + 10.

    010203002468takings, $ hundredvisitors, hundredall 8 days: y = x + 16the other 7: y = 3x + 10
    010203002468takings, $ hundredvisitors, hundredall 8 days: y = x + 16the other 7: y = 3x + 10
    (a) The two lines: y = x + 16 through all eight days and y = 3x + 10 through the seven ordinary ones.
  6. 6.(b) At 600 visitors, x = 6. The first line gives 6 + 16 = 22 hundred dollars, that is $2200, and the second gives 3 × 6 + 10 = 28 hundred dollars, that is $2800. Use $2800, because the question asks about an ordinary day and the power cut day is not one, so it should not be shaping the line. Check: the day that really had 600 visitors took 28 hundred dollars, which the second line matches exactly.

    010203002468takings, $ hundredvisitors, hundred6 + 16 = 22, that is $22003 × 6 + 10 = 28, that is $2800
    010203002468takings, $ hundredvisitors, hundred6 + 16 = 22, that is $22003 × 6 + 10 = 28, that is $2800
    (b) Reading up at 6 hundred visitors: 22 hundred dollars off the first line and 28 hundred off the second, that is $2200 against $2800.

Answer: (a) the mean point of all eight days is (4.5, 20.5), giving y = x + 16, and without the power cut day it is (4, 22), giving y = 3x + 10; (b) $2200 from the first line and $2800 from the second, and the second is the one to use

Common mistakes

  • Deleting the outlier simply because it is far from the others. A point is left out only when something outside the numbers explains it, and here there is such a reason: the shop was shut for half the day. An outlier with no explanation is real data and stays in.
  • Assuming that one day in eight can hardly matter. It pulls the gradient from 3 down to 1 and moves the estimate by $600, because it lies at the far right of the diagram, where a point has the most leverage on a line.

More scatter plots and correlation problems, worked step by step →

Practice Line of Best Fit in the app