5.5: Fitting a Line to Data
Learning Objectives
- Make a scatter plot.
- Fit a line to data and write an equation for that line.
- Perform linear regression with a graphing calculator.
- Solve real-world problems using linear models of scattered data.
Introduction
Often in application problems, the relationship between our dependent and independent variables is linear. That means that the graph of the dependent variable vs. independent variable will be a straight line. In many cases we don’t know the equation of the line but we have data points that were collected from measurements or experiments. The goal of this section is to show how we can find an equation of a line from data points collected from experimental measurements.
Make a Scatter Plot
A scatter plot is a plot of all the ordered pairs in the table. This means that a scatter plot is a relation, and not necessarily a function. Also, the scatter plot is discrete, as it is a set of distinct points. Even when we expect the relationship we are analyzing to be linear, we should not expect that all the points would fit perfectly on a straight line. Rather, the points will be “scattered” about a straight line. There are many reasons why the data does not fall perfectly on a line such as measurement error and outliers.
Measurement error is always present as no measurement device is perfectly accurate. In measuring length, for example, a ruler with millimeter markings will be more accurate than a ruler with just centimeter markings.
An outlier is an accurate measurement that does not fit with the general pattern of the data. It is a statistical fluctuation like rolling a die ten times and getting the six side all ten times. It can and will happen, but not very often.
Example 1
Make a scatter plot of the following ordered pairs: (0, 2), (1, 4.5), (2, 9), (3, 11), (4, 13), (5, 18), (6, 19.5)
Solution
We make a scatter plot by graphing all the ordered pairs on the coordinate axis.
Fit a Line to Data
Notice that the points look like they might be part of a straight line, although they would not fit perfectly on a straight line. If the points were perfectly lined up it would be quite easy to draw a line through all of them and find the equation of that line. However, if the points are “scattered”, we try to find a line that best fits the data.
You see that we can draw many lines through the points in our data set. These lines have equations that are very different from each other. We want to use the line that is closest to all the points on the graph. The best candidate in our graph is the red line . We want to minimize the sum of the distances from the point to the line of fit as you can see in the figure below.
Finding this line mathematically is a complex process and is not usually done by hand. We usually “eye-ball” the line or find it exactly by using a graphing calculator or computer software such as Excel. The line in the graph above is “eye-balled,” which means we drew a line that comes closest to all the points in the scatter plot.
When we use the line of best fit we are assuming that there is a continuous linear function that will approximate the discrete values of the scatter plot. We can use this to interpret unknown values.
Write an Equation for a Line of Best Fit
Once you draw the line of best fit, you can find its equation by using two points on the line. Finding the equation of the line of best fit is also called linear regression.
Caution: Make sure you don’t get caught making a common mistake. In many instances the line of best fit will not pass through many or any of the points in the original data set. This means that you can’t just use two random points from the data set. You need to use two points that are on the line.
We see that two of the data points are very close to the line of best fit, so we can use these points to find the equation of the line (1, 4.5) and (3, 11).
Start with the slope-intercept form of a line .
Find the slope
Then
Plug (3, 11) into the equation.
The equation for the line that fits the data best is .
Perform Linear Regression with a Graphing Calculator
Drawing a line of fit can be a good approximation but you can't be sure that you are getting the best results because you are guessing where to draw the line. Two people working with the same data might get two different equations because they would be drawing different lines. To get the most accurate equation for the line, we can use a graphing calculator. The calculator uses a mathematical algorithm to find the line that minimizes the sum of the squares.
Example 2
Use a graphing calculator to find the equation of the line of best fit for the following data (3, 12), (8, 20), (1, 7), (10, 23), (5, 18), (8, 24), (11, 30), (2, 10).
Solution
Step 1 Input the data in your calculator.
Press [STAT] and choose the [EDIT] option.
Input the data into the table by entering the values in the first column and the values in the second column.
Step 2 Find the equation of the line of best fit.
Press [STAT] again use right arrow to select [CALC] at the top of the screen.
Chose option number 4: and press [ENTER]
The calculator will display
Press [ENTER] and you will be given the and values.
Here represents the slope and represents the intercept of the equation. The linear regression line is .
Step 3 Draw the scatter plot.
To draw the scatter plot press [STATPLOT] [2nd] [Y=].
Choose Plot 1 and press [ENTER].
Press the On option and choose the Type as scatter plot (the one highlighted in black).
Make sure that the list and list names match the names of the columns of the table in Step 1.
Choose the box or plus as the mark since the simple dot may make it difficult to see the points.
Press [GRAPH] and adjust the window size so you can see all the points in the scatter plot.
Step 4 Draw the line of best fit through the scatter plot.
Press [Y=]
Enter the equation of the line of best fit that you just found
Press [GRAPH].
Solve Real-World Problems Using Linear Models of Scattered Data
In a real-world problem, we use a data set to find the equation of the line of best fit. We can then use the equation to predict values of the dependent or independent variables. The usual procedure is as follows.
- Make a scatter plot of the given data.
- Draw a line of best fit.
- Find an equation of a line either using two points on the line or the TI-83/84 calculator.
- Use the equation to answer the questions asked in the problem.
Example 3
Gal is training for a 5 K race (a total of 5000 meters, or about 3.1 miles). The following table shows her times for each month of her training program. Assume here that her times will decrease in a straight line with time (does that seem like a good assumption?) Find an equation of a line of fit. Predict her running time if her race is in August.
Month | Month number | Average time (minutes) |
---|---|---|
January | 0 | 40 |
February | 1 | 38 |
March | 2 | 39 |
April | 3 | 38 |
May | 4 | 33 |
June | 5 | 30 |
Solution
Let’s make a scatter plot of Gal’s running times. The independent variable, , is the month number and the dependent variable, , is the running time in minutes. We plot all the points in the table on the coordinate plane.
Draw a line of fit.
Choose two points on the line (0, 41) and (4, 34).
Find the equation of the line.
In a real-world problem, the slope and intercept have a physical significance.
Since the slope is negative, the number of minutes Gal spends running a 5 K race decreased as the months pass. The slope tells us that Gal’s running time decreases by or 1.75 minutes per month.
The intercept tells us that when Gal started training, she ran a distance of 5 K in 41 minutes, which is just an estimate, since the actual time was 40 minutes.
The problem asks us to predict Gal’s running time in August. Since June is assigned to month number five, then August will be month number seven. We plug into the equation of the line of best fit.
The equation predicts that Gal will be running the 5 K race in 28.75 minutes.
In this solution, we eye-balled a line of best fit. Using a graphing calculator, we found this equation for a line of fit .
If we plug in this equation, we get . This means that Gal ran her race in 28.3 minutes. You see that the graphing calculator gives a different equation and a different answer to the question. The graphing calculator result is more accurate but the line we drew by hand still gives a good approximation to the result.
Example 4
Baris is testing the burning time of “BriteGlo” candles. The following table shows how long it takes to burn candles of different weights. Assume it’s a linear relation and we can then use a line to fit the data. If a candle burns for 95 hours, what must be its weight in ounces?
Candle weight (oz) | Time (hours) |
---|---|
2 | 15 |
3 | 20 |
4 | 35 |
5 | 36 |
10 | 80 |
16 | 100 |
22 | 120 |
26 | 180 |
Solution
Let’s make a scatter plot of the data. The independent variable, , is the candle weight in ounces and the dependent variable, , is the time in hours it takes the candle to burn. We plot all the points in the table on the coordinate plane.
Then we draw the line of best fit.
Now pick two points on the line (0,0) and (30, 200).
Find the equation of the line:
In this problem the slope is burning time divided by candle weight. A slope of tells us for each extra ounce of candle weight, the burning time increases by .
A intercept of zero tells us that a candle of weight 0 oz will burn for 0 hours.
The problem asks for the weight of a candle that burns 95 hours. We are given the value of . We need to use the equation to find the corresponding value of .
A candle that burns 95 hours weighs 14.25 oz.
The graphing calculator gives the linear regression equation as and a result of 14.6 oz.
Notice that we can use the line of best fit to estimate the burning time for a candle of any weight.
Lesson Summary
- A scatter plot is a plot of all ordered pairs of experimental measurements.
- Measurement error arises from inaccuracies in the measurement device. All measurements of continuous values contain measurement error.
- An outlier is an experimental measurement that does not fit with the general pattern of the data.
- For experimental measurements with a linear relationship, you can draw a line of best fit which minimizes the distance of each point to the line. Finding the line of best fit is called linear regression. A statistics class can teach you the math behind linear regression. For now, you can estimate it visually or use a graphing calculator.
Review Questions
For each data set, draw the scatter plot and find the equation of the line of best fit for the data set by hand.
- (57, 45) (65, 61) (34, 30) (87, 78) (42, 41) (35, 36) (59, 35) (61, 57) (25, 23) (35, 34)
- (32, 43) (54, 61) (89, 94) (25, 34) (43, 56) (58, 67) (38, 46) (47, 56) (39, 48)
- (12, 18) (5, 24) (15, 16) (11, 19) (9, 12) (7, 13) (6, 17) (12, 14)
- (3, 12) (8, 20) (1, 7) (10, 23) (5, 18) (8, 24) (2, 10)
For each data set, use a graphing calculator to find the equation of the line of best fit.
- (57, 45) (65, 61) (34, 30) (87, 78) (42, 41) (35, 36) (59, 35) (61, 57) (25, 23) (35, 34)
- (32, 43) (54, 61) (89, 94) (25, 34) (43, 56) (58, 67) (38, 46) (47, 56) (95, 105) (39, 48)
- (12, 18) (3, 26) (5, 24) (15, 16) (11, 19) (0, 27) (9, 12) (7, 13) (6, 17) (12, 14)
- Shiva is trying to beat the samosa eating record. The current record is 53.5 samosas in 12 minutes. The following table shows how many samosas he eats during his daily practice for the first week of his training. Will he be ready for the contest if it occurs two weeks from the day he started training? What are the meanings of the slope and the intercept in this problem?
Day | No. of Samosas |
---|---|
1 | 30 |
2 | 34 |
3 | 36 |
4 | 36 |
5 | 40 |
6 | 43 |
7 | 45 |
- Nitisha is trying to find the elasticity coefficient of a Superball. She drops the ball from different heights and measures the maximum height of the resulting bounce. The table below shows her data. Draw a scatter plot and find the equation. What is the initial height if the bounce height is 65 cm? What are the meanings of the slope and the intercept in this problem?
Initial height (cm) | Bounce height (cm) |
---|---|
30 | 22 |
35 | 26 |
40 | 29 |
45 | 34 |
50 | 38 |
55 | 40 |
60 | 45 |
65 | 50 |
70 | 52 |
- The following table shows the median California family income from 1995 to 2002 as reported by the US Census Bureau. Draw a scatter plot and find the equation. What would you expect the median annual income of a Californian family to be in year 2010? What are the meanings of the slope and the intercept in this problem?
Year | Income |
---|---|
1995 | 53807 |
1996 | 55217 |
1997 | 55209 |
1998 | 55415 |
1999 | 63100 |
2000 | 63206 |
2001 | 63761 |
2002 | 65766 |
Review Answers
- Solution . Shiva will beat the record.
- slope = the ratio of bounce height to drop height intercept = how far the ball bounces if it’s dropped from a height of zero. The line is the best fit to the data. We know that dropping it from height of zero should give a bounce of zero and -0.5 cm is pretty close to zero. Drop height when bounce height
- years since 1995 Income in thousands of dollars slope = increase in income per year (in thousands) intercept = income in 1995 (in thousands) Income in 2010 is $80050.