Chapter 14 · Statistics and data analysis

Lines of Best Fit: Choose a Line and Judge Its Fit

Learn why a straight line can model paired data, how to pick the line the points stay closest to, and how to judge how well a line fits.

20 min read

Often you collect two numbers about the same thing. Bivariate data are data made of such pairs: two quantities measured for each person or object. A coach records two numbers for each of 8 players. The first is xx, the hours the player practiced free throws in one week, from 11 to 88 hours here. The second is yy, the number of free throws the player then made out of 2020 shots, a whole number from 00 to 2020. The 8 pairs (x,y)(x, y) are (1,5)(1, 5), (2,5)(2, 5), (3,9)(3, 9), (4,10)(4, 10), (5,11)(5, 11), (6,15)(6, 15), (7,15)(7, 15) and (8,18)(8, 18). In the scatter plot below, the horizontal axis shows hours of practice and the vertical axis shows free throws made. The plot also shows Line A, the line with equation y=2x+2y = 2x + 2.

Coordinate grid from x 0 to 9 and y 0 to 20, with a grid step of 1, showing 9 plotted elements. Details: point at (1, 5); point at (2, 5); point at (3, 9); point at (4, 10); point at (5, 11); point at (6, 15); point at (7, 15); point at (8, 18); line 2 x plus -1 y equals -2, named Line A.
Each point is one player. Line A, y=2x+2y = 2x + 2, runs close to all 8 points but passes exactly through only (4,10)(4, 10) and (8,18)(8, 18).

Look at the overall shape. As xx increases, yy tends to increase, and the points appear to climb along a roughly straight path instead of curving. You will check this with exact numbers below. Along a straight line such as Line A, yy changes by exactly the same amount for each step of 11 in xx. Line A's yy-values at x=1,2,3,…x = 1, 2, 3, \dots are 4,6,8,…4, 6, 8, \dots, so they go up exactly 22 each time. When points follow a roughly straight path, one line with one simple equation can describe the whole trend. That line is a model: a simplified description of the data. A straight line that the points stay close to overall is called a line of best fit. Line A's equation is exact, but its fit to the players is only approximate. Real data scatter around a trend, so most of these points sit a little above or below the line.

To measure how close a point is to a line, use its vertical gap: the point's yy-value minus the line's yy-value at the same xx. You find the line's yy-value by substituting the point's xx into the line's equation. A positive gap means the point is above the line, and a negative gap means it is below. A gap of 00 means the point is on the line. The size of a gap is its distance from 00, so a gap of −3-3 has size 33.

Worked example

Find one vertical gap

Line A has equation y=2x+2y = 2x + 2. One player practiced 66 hours and made 1515 free throws, which is the point (6,15)(6, 15). What is this point's vertical gap from Line A?

  1. Every point on Line A has a yy-value equal to 2x+22x + 2. Substitute x=6x = 6 to find the line's yy-value at 66 hours.

    yline=2(6)+2=12+2=14y_{\text{line}} = 2(6) + 2 = 12 + 2 = 14
  2. Subtract the line's value from the data value. Keep this order, data minus line, so that points above the line get positive gaps.

    gap=15−14=1\text{gap} = 15 - 14 = 1
  3. Read the result. The gap is positive, so the point is 11 free throw above the line. The value 1414 is exact for Line A, but as a description of this player it is only approximate.

Answer

The point (6,15)(6, 15) has a vertical gap of 11, so it lies 11 free throw above Line A.

Many different lines can be drawn through the same scatter plot, so you need a way to decide which one fits best. A classmate suggests Line B, y=x+6y = x + 6, because it passes exactly through three players' points: (3,9)(3, 9), (4,10)(4, 10) and (5,11)(5, 11). Line A passes exactly through only two, (4,10)(4, 10) and (8,18)(8, 18). The figure below shows both lines with the same 8 points. The table after it lists every player's exact vertical gap from each line.

Coordinate grid from x 0 to 9 and y 0 to 20, with a grid step of 1, showing 10 plotted elements. Details: point at (1, 5); point at (2, 5); point at (3, 9); point at (4, 10); point at (5, 11); point at (6, 15); point at (7, 15); point at (8, 18); line 2 x plus -1 y equals -2, named Line A; line 1 x plus -1 y equals -6, named Line B.
The same 8 players with two candidate lines: Line A is y=2x+2y = 2x + 2 and Line B is y=x+6y = x + 6. The lines cross at the data point (4,10)(4, 10).
Exact vertical gaps for all 8 players: data value minus the line's value at the same xx
Hours xxFree throws yyGap from Line A: y−(2x+2)y - (2x + 2)Gap from Line B: y−(x+6)y - (x + 6)
11
55
5−4=15 - 4 = 1
5−7=−25 - 7 = -2
22
55
5−6=−15 - 6 = -1
5−8=−35 - 8 = -3
33
99
9−8=19 - 8 = 1
9−9=09 - 9 = 0
44
1010
10−10=010 - 10 = 0
10−10=010 - 10 = 0
55
1111
11−12=−111 - 12 = -1
11−11=011 - 11 = 0
66
1515
15−14=115 - 14 = 1
15−12=315 - 12 = 3
77
1515
15−16=−115 - 16 = -1
15−13=215 - 13 = 2
88
1818
18−18=018 - 18 = 0
18−14=418 - 14 = 4

Worked example

Compare two candidate lines

Use the table to decide which candidate, Line A or Line B, is the better line of fit for all 8 players.

  1. One informal way to judge closeness overall is to add the sizes of the gaps. Use sizes, not signed gaps. A point 33 below a line is as far from it as a point 33 above, and signed gaps of −3-3 and 33 would cancel to 00 and hide both misses. Start with Line A.

    1+1+1+0+1+1+1+0=6\begin{aligned} &1 + 1 + 1 + 0 \\ &{}+ 1 + 1 + 1 + 0 \\ &= 6 \end{aligned}
  2. Add the sizes of Line B's gaps the same way, so both lines are measured by the same rule. Then compare the totals.

    2+3+0+0+0+3+2+4=14,6<14\begin{aligned} &2 + 3 + 0 + 0 \\ &{}+ 0 + 3 + 2 + 4 \\ &= 14, \end{aligned} \qquad 6 < 14
  3. As a second check, compare the largest single miss, which shows the worst a line does for any one player. Line A misses no player by more than 11 free throw. Line B misses the player who practiced 88 hours by 44.

    1<41 < 4
  4. Look at where Line B misses. Points sit below it on the left, with gaps −2-2 and −3-3, and above it on the right, with gaps 33, 22 and 44. This pattern shows that Line B is too flat to follow the climb of the data.

Answer

Line A is the better line of fit. Its gap sizes total 66 free throws and none is more than 11, while Line B's total 1414 and reach 44, even though Line B passes through more points.

Real data rarely sit exactly on a line, so the real question is how well a line fits. You can assess a line with two informal checks on its gaps.

  • Size: Are the gaps small compared with the spread of the data?
  • Pattern: Are points above and below the line mixed all along it? Or do they sit on one side in some places and on the other side elsewhere?

For the free throws, Line A's gaps are only 11, −1-1 or 00. That is small next to the spread of free throws from 55 to 1818. The signs of the gaps mix with no pattern, so Line A fits well.

Points on both sides of a line are a helpful sign. But the counts on each side do not need to match, and balance alone proves nothing. Line B has 22 points below it and 33 above, yet it fits poorly.

Key concept

A line of best fit is an approximate model

When the points of a scatter plot follow a roughly straight path, a straight line can model how the two quantities change together. Choose and judge a line by how close all the points stay to it, using their vertical gaps. Do not judge it by how many points it passes through. A good fit has gaps that are small and mixed above and below. If the points bend away from the line, a straight line is a poor model. The line's equation is exact, but its fit is approximate. Points on both sides are a helpful sign, not a rule that the counts must be equal. A good fit shows that the quantities go together, not that one causes the other.

vertical gap=ydata−yline\text{vertical gap} = y_{\text{data}} - y_{\text{line}}

Now look at a different data set. Here xx and yy are plain numbers with no units, and xx runs from 11 to 88. The 8 points are (1,1)(1, 1), (2,6)(2, 6), (3,10)(3, 10), (4,13)(4, 13), (5,15)(5, 15), (6,16)(6, 16), (7,16)(7, 16) and (8,15)(8, 15). Someone models these data with Line C, y=2x+3y = 2x + 3. In the figure below, the horizontal axis shows xx and the vertical axis shows yy.

Coordinate grid from x 0 to 9 and y 0 to 20, with a grid step of 1, showing 9 plotted elements. Details: point at (1, 1); point at (2, 6); point at (3, 10); point at (4, 13); point at (5, 15); point at (6, 16); point at (7, 16); point at (8, 15); line 2 x plus -1 y equals -3, named Line C.
The second data set: the points climb from (1,1)(1, 1), level off at y=16y = 16 for x=6x = 6 and x=7x = 7, then dip to (8,15)(8, 15). Line C is y=2x+3y = 2x + 3.

Worked example

Assess a line on bending data

Assess how well Line C, y=2x+3y = 2x + 3, fits the 8 points of the second data set.

  1. Each gap needs the line's value at the same xx. Find Line C's yy-value at each xx from 11 to 88 by substituting into y=2x+3y = 2x + 3. For example, at x=1x = 1 the value is 2(1)+3=52(1) + 3 = 5.

    5, 7, 9, 11, 13, 15, 17, 195,\ 7,\ 9,\ 11,\ 13,\ 15,\ 17,\ 19
  2. Subtract each line value from the data value at the same xx to get the vertical gaps.

    1−5=−4, 6−7=−1, 10−9=1, 13−11=2, 15−13=2, 16−15=1, 16−17=−1, 15−19=−41-5=-4,\ 6-7=-1,\ 10-9=1,\ 13-11=2,\ 15-13=2,\ 16-15=1,\ 16-17=-1,\ 15-19=-4
  3. Check the size. Add the gap sizes, ignoring signs. The total is 1616, and two points miss by 44. That is a big miss when the yy-values only run from 11 to 1616.

    4+1+1+2+2+1+1+4=16\begin{aligned} &4 + 1 + 1 + 2 \\ &{}+ 2 + 1 + 1 + 4 \\ &= 16 \end{aligned}
  4. Check the pattern. The gaps are negative at x=1x = 1 and 22, positive from x=3x = 3 to 66, and negative again at x=7x = 7 and 88. So the points sit below the line at both ends and above it in the middle. Exactly 44 points are above and 44 below, so the balance looks fine, yet the points bend away from the line.

  5. Compare the rises to see why. Line C changes by the same amount at every step: exactly 22 each time xx grows by 11. The data rise by 5,4,3,2,1,05, 4, 3, 2, 1, 0 and then fall by 11, shrinking at every step. The free-throw rises jumped between 00 and 44 with no steady trend. Rises that shrink steadily trace a curve, and a straight line cannot bend to follow it.

    6−1=5, 10−6=4, 13−10=3, 15−13=2, 16−15=1, 16−16=0, 15−16=−16-1=5,\ 10-6=4,\ 13-10=3,\ 15-13=2,\ 16-15=1,\ 16-16=0,\ 15-16=-1

Answer

Line C is a poor fit. Its misses reach 44, and the points fall below, then above, then below the line, so a straight line is not a good model for this data set.

Takeaway: When the points of a scatter plot follow a roughly straight path, a straight line can model how the two quantities change together. To choose among lines, pick the one all the points stay closest to, measured by vertical gaps. Do not pick the one that passes through the most points. To judge a fit, check the size and pattern of the gaps. Small, mixed gaps mean a good approximate fit, while points that bend away mean a straight line is a poor model. Even a good fit shows only that two quantities go together, not that one causes the other. Next, you will fit a line to a scatter plot yourself and write an equation for a line of best fit.