Chapter 14 ยท Statistics and data analysis
Fit a Line and Write Its Equation
Draw a line of best fit by eye so it runs close to all the points, then use two exact points on your line to write its equation.
Earlier in this topic, you judged which line fits a scatter plot best. Now you will fit a line yourself and then write its equation.
A scatter plot shows paired measurements as points. When the points fall roughly along a straight path, the data have a linear trend, and a straight line can model it. A line of best fit is a straight line that follows that trend closely. You fit it informally, by eye, so it is an approximate model of the data. You judge it by how close it runs to all the points, not by whether it passes through them. It may pass through a few points or through none. Two careful people may draw slightly different lines that both fit well.
Here is a data set to fit. On a clear winter day, a weather station recorded the air temperature once an hour. Let be the number of hours after 6 a.m., and let be the temperature in degrees Celsius (ยฐC). The readings run from 6 a.m. () to 2 p.m. (), so a line fitted to them describes the data only for from to . Below freezing, Celsius temperatures are negative, so can be negative or positive. Call this day Day 1. The table lists the readings. The scatter plot after it shows them, with on the horizontal axis and on the vertical axis.
| Hours after 6 a.m., | Temperature in ยฐC, |
|---|---|
Worked example
Fit a line to the Day 1 data
Fit a straight line to the Day 1 scatter plot above. The horizontal axis is (hours after 6 a.m.) and the vertical axis is (temperature in ยฐC). Then check how well your line fits.
Check that a straight line makes sense. From x = 0 to x = 8 the temperatures climb from -7 to 5. The points rise along a roughly straight path rather than a curve, so a straight line can model this linear trend.
Aim at the whole cloud of points. Imagine laying a ruler so it rises as the points do. Then slide it to the middle of the cloud, so the points sit close to it on both sides. To keep the line exact, settle on one that passes through grid points, where grid lines cross. Line A passes through (0, -6) and (8, 6).
Find Line A's height (its y-value) at each hour. It rises 12 degrees over 8 hours, or 3 degrees every 2 hours, so it passes through (2, -3), (4, 0) and (6, 3). A straight line changes height at a steady rate. So at each odd hour it is halfway between the heights an hour before and after: -4.5 at x = 1, then -1.5, 1.5 and 4.5 at x = 3, 5 and 7.
Measure each gap: the temperature minus the line's height at that hour. A positive gap means the point is above the line, and a negative gap means it is below. From x = 0 to x = 8 the gaps are -1, 0.5, 1, -0.5, 0, 0.5, 1, -0.5 and -1.
Judge the fit. Every gap is between -1 and 1, so every reading lies within 1 degree of Line A. Four points are above it and four are below. One point, (4, 0), happens to lie on it. The points stay close on both sides, so Line A is a reasonable fit, though not the only possible one.
Answer
Line A, through and , is a reasonable line of best fit for Day 1, because every reading lies within degree of it.
Once you have chosen a line, you can write its equation. The equation must describe the line you drew, not the data. Data points usually sit off your line, and a line through two points that are off it is a different line.
- The slope is the change in divided by the change in between two points and on the line. The points need different -values, so you never divide by zero. A line that rises from left to right has a positive slope, and one that falls has a negative slope.
- The -intercept is the value of where the line crosses the -axis, that is, where .
Every line that is not vertical has an equation . At it gives , and each increase of in changes by . Grid points on your line give you exact coordinates to use.
Key concept
An approximate fit, an exact line
A line of best fit is a straight line you choose by eye to follow a linear trend. You judge it by how close it runs to all the plotted points, and it need not pass through any of them. Having points fall roughly evenly on both sides is a helpful guide, not a rule: a line tilted the wrong way can still split the points evenly. The fit is approximate, but the line you choose is exact. Use two points on it to find and , and write . The line describes how the two quantities change together. It does not show that one causes the other.
Worked example
Write the equation of Line A
Write an equation for Line A, the Day 1 line of best fit through the grid points and .
Choose two points on the line itself. Use (0, -6) and (8, 6): both lie exactly on Line A, and their x-values differ. The readings at those hours, (0, -7) and (8, 5), are off Line A. Using them would give the equation of Line B instead.
Find the slope, subtracting in the same order on top and bottom. Subtracting -6 is the same as adding 6. The bottom is 8, not 0, so the division is defined. Dividing the top and bottom of 12/8 by 4 keeps its value. The result matches the 3 degrees every 2 hours you found while fitting.
Find the y-intercept. Line A crosses the y-axis exactly at the grid point (0, -6), where x = 0, so b = -6.
Substitute m = 1.5 and b = -6 into y = mx + b. Adding -6 is the same as subtracting 6.
Check with a third point on Line A, the grid point (6, 3). Substituting x = 6 should give y = 3. It does, so the equation matches the line.
Answer
An equation for Line A is , where is hours after 6 a.m. (from to ) and is the temperature in ยฐC.
On Day 2, a cold front arrived at the same station, and the temperature fell instead. The variables are the same. The horizontal axis shows , hours after 6 a.m., from to . The vertical axis shows , the temperature in ยฐC. The readings were , , , , , , , and .
Time passed in the same way on both days, yet the temperature rose on one day and fell on the other. A trend between two quantities does not show that one causes the other. Here the weather, not the clock, changed the temperature.
Worked example
Fit a line to Day 2 and write its equation
Fit a line to the Day 2 scatter plot above, then write an equation for your line.
Fit the line first. The points fall from left to right along a roughly straight path, so tilt the ruler downward and slide it to the middle of the cloud. Line C passes through the grid points (1, 4) and (7, -5), and it runs close to the points on both sides.
Find the slope from those two points on the line. The line falls, so expect a negative slope. The x-values differ by 6, not 0.
Find b. Line C crosses the y-axis between grid lines, so reading b from the picture would give only an estimate. Every point on the line makes its equation true. So substitute m = -1.5 and the point (1, 4) into y = mx + b.
Add 1.5 to both sides. Adding the same number to both sides keeps them equal, and it leaves b by itself.
Write the equation, then check it with the other point, (7, -5). Substituting x = 7 gives -5, so the equation describes Line C exactly.
Use the equation to check the fit. Substituting x = 0 to 8 gives the line's heights: 5.5, 4, 2.5, 1, -0.5, -2, -3.5, -5 and -6.5. The gaps from the readings are 0.5, -1, 0.5, 1, -0.5, -1, 0.5, 1 and -0.5. Every reading is within 1 degree, with five points above and four below.
Answer
Line C is a reasonable line of best fit for Day 2, and an equation for it is , with in hours after 6 a.m. (from to ) and in ยฐC.
To fit a line, aim it along the trend of the whole cloud and check that the points sit close to it. Points roughly on both sides are a helpful guide. The fit is approximate, and the line shows a trend, not a cause. Once you choose a line through two exact points, though, its equation is exact.