maths.free › Algebra › 4. Linear Functions › Fitting Linear Models to Data
Fitting Linear Models to Data
Draw and interpret scatter diagrams.
Drawing and Interpreting Scatter Plots
A scatter plot is a graph of plotted points that may show a relationship between two sets of data. If the relationship is from a linear model, or a model that is nearly linear, the professor can draw conclusions using his knowledge of linear functions. shows a sample scatter plot.
Notice this scatter plot does not indicate a linear relationship. The points do not appear to follow a trend. In other words, there does not appear to be a relationship between the age of the student and the score on the final exam.
Example
Try it.
The table below shows the number of cricket chirps in 15 seconds, for several different air temperatures, in degrees FahrenheitSelected data from http://classic.globe.gov/fsl/scientistsblog/2007/10/. Retrieved Aug 3, 2010. Plot this data, and determine whether the data appears to be linearly related.
| Chirps | 44 | 35 | 20.4 | 33 | 31 | 35 | 18.5 | 37 | 26 |
| Temperature | 80.5 | 70.5 | 57 | 66 | 68 | 72 | 52 | 73.5 | 53 |
Solution
Plotting this data, as depicted in suggests that there may be a trend. We can see from the trend in the data that the number of chirps increases as the temperature increases. The trend appears to be roughly linear, though certainly not perfectly so.
Finding the Line of Best Fit
Once we recognize a need for a linear function to model that data, the natural follow-up question is “what is that linear function?” One way to approximate our linear function is to sketch the line that seems to best fit the data. Then we can extend the line until we can verify the y-intercept. We can approximate the slope of the line by extending it until we can estimate the \(\frac{\text{rise}}{\text{run}}.\)
Example
Try it.
Find a linear function that fits the data in by “eyeballing” a line that seems to fit.
Solution
On a graph, we could try sketching a line. Using the starting and ending points of our hand drawn line, points (0, 30) and (50, 90), this graph has a slope of
\[\begin{array}{lll}m & = & \frac{60}{50} \\ & = & 1.2\end{array}\]and a y-intercept at 30. This gives an equation of
\[T(c)=1.2c+30\]where \(c\) is the number of chirps in 15 seconds, and \(T(c)\) is the temperature in degrees Fahrenheit. The resulting equation is represented in .
While eyeballing a line works reasonably well, there are statistical techniques for fitting a line to data that minimize the differences between the line and data valuesTechnically, the method minimizes the sum of the squared differences in the vertical direction between the line and the data values.. One such technique is called least squares regression and can be computed by many graphing calculators, spreadsheet software, statistical software, and many web-based calculatorsFor example, http://www.shodor.org/unchem/math/lls/leastsq.html. Least squares regression is one means to determine the line that best fits the data, and here we will refer to this method as linear regression.
Example
Try it.
Find the least squares regression line using the cricket-chirp data in .
Solution
- Enter the input (chirps) in List 1 (L1).
- Enter the output (temperature) in List 2 (L2). See .
L1 44 35 20.4 33 31 35 18.5 37 26 L2 80.5 70.5 57 66 68 72 52 73.5 53 - On a graphing utility, select Linear Regression (LinReg). Using the cricket chirp data from earlier, with technology we obtain the equation:
Condensed — the full section is in OpenStax College Algebra 2e.
Distinguishing Between Linear and Nonlinear Models
As we saw above with the cricket-chirp model, some data exhibit strong linear trends, but other data, like the final exam scores plotted by age, are clearly nonlinear. Most calculators and computer software can also provide us with the correlation coefficient, which is a measure of how closely the line fits the data. Many graphing calculators require the user to turn a "diagnostic on" selection to find the correlation coefficient, which mathematicians label as \(r\) The correlation coefficient provides an easy way to get an idea of how close to a line the data falls.
We should compute the correlation coefficient only for data that follows a linear pattern or to determine the degree to which a data set is linear. If the data exhibits a nonlinear pattern, the correlation coefficient for a linear regression is meaningless. To get a sense for the relationship between the value of \(r\) and the graph of the data, shows some large data sets with their correlation coefficients. Remember, for all plots, the horizontal axis shows the input and the vertical axis shows the output.
Example
Try it.
Calculate the correlation coefficient for cricket-chirp data in .
Solution
Because the data appear to follow a linear pattern, we can use technology to calculate \(r\) Enter the inputs and corresponding outputs and select the Linear Regression. The calculator will also provide you with the correlation coefficient, \(r=0.9509.\) This value is very close to 1, which suggests a strong increasing linear relationship.
Note: For some calculators, the Diagnostics must be turned "on" in order to get the correlation coefficient when linear regression is performed: [2nd]>[0]>[alpha][x–1], then scroll to DIAGNOSTICSON.
Fitting a Regression Line to a Set of Data
Once we determine that a set of data is linear using the correlation coefficient, we can use the regression line to make predictions. As we learned above, a regression line is a line that is closest to the data in the scatter plot, which means that only one such line is a best fit for the data.
Example
Try it.
Gasoline consumption in the United States has been steadily increasing. Consumption data from 1994 to 2004 is shown in .http://www.bts.gov/publications/national_transportation_statistics/2005/html/table_04_10.html Determine whether the trend is linear, and if so, find a model for the data. Use the model to predict the consumption in 2008.
| Year | '94 | '95 | '96 | '97 | '98 | '99 | '00 | '01 | '02 | '03 | '04 |
| Consumption (billions of gallons) | 113 | 116 | 118 | 119 | 123 | 125 | 126 | 128 | 131 | 133 | 136 |
The scatter plot of the data, including the least squares regression line, is shown in .
Solution
We can introduce a new input variable, \(t,\) representing years since 1994.
The least squares regression equation is:
\[C(t)=113.318+2.209t\]Using technology, the correlation coefficient was calculated to be 0.9965, suggesting a very strong increasing linear trend.
Using this to predict consumption in 2008 \((t=14),\)
\[\begin{array}{l}C(14)=113.318+2.209(14) \\ \ =144.244\end{array}\]The model predicts 144.244 billion gallons of gasoline consumption in 2008.
Key Concepts
- Scatter plots show the relationship between two sets of data. See .
- Scatter plots may represent linear or non-linear models.
- The line of best fit may be estimated or calculated, using a calculator or statistical software. See .
- Interpolation can be used to predict values inside the domain and range of the data, whereas extrapolation can be used to predict values outside the domain and range of the data. See .
- The correlation coefficient, \(r,\) indicates the degree of linear relationship between data. See .
- A regression line best fits the data. See .
- The least squares regression line is found by minimizing the squares of the distances of points from a line passing through the data and may be used to make predictions regarding either of the variables. See .
Chapter Practice Test
For the following exercises, determine whether the lines given by the equations below are parallel, perpendicular, or neither parallel nor perpendicular.
For the following exercises, use the graph in , showing the profit, \(y,\) in thousands of dollars, of a company in a given year, \(x,\) where \(x\) represents years since 1980.
For the following exercises, use , which shows the percent of unemployed persons 25 years or older who are college graduates in a particular city, by year.
| Year | 2000 | 2002 | 2005 | 2007 | 2010 |
| Percent Graduates | 8.5 | 8.0 | 7.2 | 6.7 | 6.4 |
For the following exercises, consider this scenario: The population of a city increased steadily over a ten-year span. The following ordered pairs shows the population (in hundreds) and the year over the ten-year span, (population, year) for specific recorded years:
\((4,500,2000);(4,700,2001);(5,200,2003);(5,800,2006)\)
Practice (40)
Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.
-
The data below shows the relationship between the mass of an automobile (measured in kg) and the fuel efficiency of the car (measured in miles per gallon) for 7 automobiles.
Mass (kg), x 1305 1150 1925 1628 1506 1452 1835 Fuel Efficiency (MPG), y 27 28 15 24 23 25 19 ⓐ Draw a scatter plot (by hand or using a graphing utility) for the data provided being sure to label your axes.
ⓑ Does the data appear to be linearly related? Is the association between the variables positive or negative?
ⓒ Choose two points that seem to represent the general pattern in the data set. Write these points as ordered pairs below.
\((\ ,\ )\)
\((\ ,\ )\)ⓓ Write the equation of the line passing through the points you listed in part c. in slope intercept form. Show your work below.
ⓔ Use the linear function you found in part d. to predict the fuel efficiency of an Audi A5 Quattro whose mass is 1610 kg.
-
The data set below shows the relationship between the number of hours worked and the tips received by Nyla, a server at Pi Pizzeria.
Hours worked in a week, x 10 15 20 25 30 35 40 Tips received, y $66 $100 $118 $160 $190 $235 $272 ⓐ Draw a scatter plot (by hand or using a graphing utility) for the data provided being sure to label your axes.
ⓑ Does the data appear to be linearly related? Is the association between the variables positive or negative?
ⓒ Choose two points that seem to represent the general pattern in the data set. Write these points as ordered pairs below.
\((\ ,\ )\)
\((\ ,\ )\)ⓓ Write the equation of the line passing through the points you listed in part c. in slope intercept form. Show your work below.
ⓔ Based on the linear function you found in part d, how much could Nyla expect to make in tips if they work 38 hours in a given week?
-
The table below shows the number of cricket chirps in 15 seconds, for several different air temperatures, in degrees FahrenheitSelected data from http://classic.globe.gov/fsl/scientistsblog/2007/10/. Retrieved Aug 3, 2010. Plot this data, and determine whether the data appears to be linearly related.
Chirps 44 35 20.4 33 31 35 18.5 37 26 Temperature 80.5 70.5 57 66 68 72 52 73.5 53 Kuratidza mhinduro
Plotting this data, as depicted in suggests that there may be a trend. We can see from the trend in the data that the number of chirps increases as the temperature increases. The trend appears to be roughly linear, though certainly not perfectly so.
-
Find a linear function that fits the data in by “eyeballing” a line that seems to fit.
Kuratidza mhinduro
On a graph, we could try sketching a line. Using the starting and ending points of our hand drawn line, points (0, 30) and (50, 90), this graph has a slope of
\[\begin{array}{lll}m & = & \frac{60}{50} \\ & = & 1.2\end{array}\]and a y-intercept at 30. This gives an equation of
\[T(c)=1.2c+30\]where \(c\) is the number of chirps in 15 seconds, and \(T(c)\) is the temperature in degrees Fahrenheit. The resulting equation is represented in .
-
Use the cricket data from to answer the following questions:
- ⓐWould predicting the temperature when crickets are chirping 30 times in 15 seconds be interpolation or extrapolation? Make the prediction, and discuss whether it is reasonable.
- ⓑWould predicting the number of chirps crickets will make at 40 degrees be interpolation or extrapolation? Make the prediction, and discuss whether it is reasonable.
Kuratidza mhinduro
- ⓐThe number of chirps in the data provided varied from 18.5 to 44. A prediction at 30 chirps per 15 seconds is inside the domain of our data, so would be interpolation. Using our model:\[\begin{array}{lll}\text{T (30)} & = & \text{30 + 1.2(30)} \\ & = & \text{66 degrees}\end{array}\]
Based on the data we have, this value seems reasonable.
- ⓑThe temperature values varied from 52 to 80.5. Predicting the number of chirps at 40 degrees is extrapolation because 40 is outside the range of our data. Using our model:\[\begin{array}{l}40=30+1.2c \\ 10=1.2c \\ \ c\approx 8.33\end{array}\]
We can compare the regions of interpolation and extrapolation using .
-
According to the data from , what temperature can we predict it is if we counted 20 chirps in 15 seconds?
Kuratidza mhinduro
\(54^{\circ}\text{F}\)
-
Find the least squares regression line using the cricket-chirp data in .
Kuratidza mhinduro
- Enter the input (chirps) in List 1 (L1).
- Enter the output (temperature) in List 2 (L2). See .
L1 44 35 20.4 33 31 35 18.5 37 26 L2 80.5 70.5 57 66 68 72 52 73.5 53 - On a graphing utility, select Linear Regression (LinReg). Using the cricket chirp data from earlier, with technology we obtain the equation:
-
Calculate the correlation coefficient for cricket-chirp data in .
Kuratidza mhinduro
Because the data appear to follow a linear pattern, we can use technology to calculate \(r\) Enter the inputs and corresponding outputs and select the Linear Regression. The calculator will also provide you with the correlation coefficient, \(r=0.9509.\) This value is very close to 1, which suggests a strong increasing linear relationship.
Note: For some calculators, the Diagnostics must be turned "on" in order to get the correlation coefficient when linear regression is performed: [2nd]>[0]>[alpha][x–1], then scroll to DIAGNOSTICSON.
-
Gasoline consumption in the United States has been steadily increasing. Consumption data from 1994 to 2004 is shown in .http://www.bts.gov/publications/national_transportation_statistics/2005/html/table_04_10.html Determine whether the trend is linear, and if so, find a model for the data. Use the model to predict the consumption in 2008.
Year '94 '95 '96 '97 '98 '99 '00 '01 '02 '03 '04 Consumption (billions of gallons) 113 116 118 119 123 125 126 128 131 133 136 The scatter plot of the data, including the least squares regression line, is shown in .
Kuratidza mhinduro
We can introduce a new input variable, \(t,\) representing years since 1994.
The least squares regression equation is:
\[C(t)=113.318+2.209t\]Using technology, the correlation coefficient was calculated to be 0.9965, suggesting a very strong increasing linear trend.
Using this to predict consumption in 2008 \((t=14),\)
\[\begin{array}{l}C(14)=113.318+2.209(14) \\ \ =144.244\end{array}\]The model predicts 144.244 billion gallons of gasoline consumption in 2008.
-
Use the model we created using technology in to predict the gas consumption in 2011. Is this an interpolation or an extrapolation?
Kuratidza mhinduro
150.871 billion gallons; extrapolation
-
Describe what it means if there is a model breakdown when using a linear model.
Kuratidza mhinduro
When our model no longer applies, after some value in the domain, the model itself doesn’t hold.
-
What is interpolation when using a linear model?
-
What is extrapolation when using a linear model?
Kuratidza mhinduro
We predict a value outside the domain and range of the data.
-
Explain the difference between a positive and a negative correlation coefficient.
-
Explain how to interpret the absolute value of a correlation coefficient.
Kuratidza mhinduro
The closer the number is to 1, the less scattered the data, the closer the number is to 0, the more scattered the data.
-
A regression was run to determine whether there is a relationship between hours of TV watched per day \((x)\) and number of sit-ups a person can do \((y).\) The results of the regression are given below. Use this to predict the number of sit-ups a person who watches 11 hours of TV can do.
\[\begin{array}{l}y=ax+b \\ a=-1.341 \\ b=32.234 \\ \ r=-0.896\end{array}\] -
A regression was run to determine whether there is a relationship between the diameter of a tree ( \(x\) , in inches) and the tree’s age ( \(y\) , in years). The results of the regression are given below. Use this to predict the age of a tree with diameter 10 inches.
\[\begin{array}{l}y=ax+b \\ a=6.301 \\ b=-1.044 \\ \ r=0.970\end{array}\]Kuratidza mhinduro
61.966 years
-
0 2 4 6 8 10 –22 –19 –15 –11 –6 –2 -
1 2 3 4 5 6 46 50 59 75 100 136 Kuratidza mhinduro
No.
-
100 250 300 450 600 750 12 12.6 13.1 14 14.5 15.2 -
1 3 5 7 9 11 1 9 28 65 125 216 Kuratidza mhinduro
No.
-
For the following data, draw a scatter plot. If we wanted to know when the population would reach 15,000, would the answer involve interpolation or extrapolation? Eyeball the line, and estimate the answer.
Year Population 1990 11,500 1995 12,100 2000 12,700 2005 13,000 2010 13,750 -
For the following data, draw a scatter plot. If we wanted to know when the temperature would reach 28°F, would the answer involve interpolation or extrapolation? Eyeball the line and estimate the answer.
Temperature,°F 16 18 20 25 30 Time, seconds 46 50 54 55 62 Kuratidza mhinduro
Interpolation. About \(60^{\circ}F.\)
-
\(r=0.\text{95}\)
-
\(r=-0.\text{89}\)
Kuratidza mhinduro
\(\text{This value of r indicates a strong negative correlation or slope, so C}\)
-
\(r=-0.26\)
-
\(r=-0.39\)
Kuratidza mhinduro
\(\text{This value of r indicates a weak negative correlation, so B}\)
-
The U.S. Census tracks the percentage of persons 25 years or older who are college graduates. That data for several years is given in .Based on data from http://www.census.gov/hhes/socdemo/education/data/cps/historical/index.html. Accessed 5/1/2014. Determine whether the trend appears linear. If so, and assuming the trend continues, in what year will the percentage exceed 35%?
Year Percent Graduates 1990 21.3 1992 21.4 1994 22.2 1996 23.6 1998 24.4 2000 25.6 2002 26.7 2004 27.7 2006 28 2008 29.4 -
The U.S. import of wine (in hectoliters) for several years is given in . Determine whether the trend appears linear. If so, and assuming the trend continues, in what year will imports exceed 12,000 hectoliters?
Year Imports 1992 2665 1994 2688 1996 3565 1998 4129 2000 4584 2002 5655 2004 6549 2006 7950 2008 8487 2009 9462 Kuratidza mhinduro
Yes, trend appears linear because \(r=0.\text{985}\) and will exceed 12,000 near midyear, 2016, 24.6 years since 1992.
-
shows the year and the number of people unemployed in a particular city for several years. Determine whether the trend appears linear. If so, and assuming the trend continues, in what year will the number of unemployed reach 5?
Year Number Unemployed 1990 750 1992 670 1994 650 1996 605 1998 550 2000 510 2002 460 2004 420 2006 380 2008 320 -
\(x\) 8 15 26 31 56 \(y\) 23 41 53 72 103 Kuratidza mhinduro
\(y=\text{1}.\text{64}0x+\text{13}.\text{8}00,\) \(r=0.\text{987}\)
-
\(x\) 5 7 10 12 15 \(y\) 4 12 17 22 24 -
\(x\) \(y\) \(x\) \(y\) 3 21.9 10 18.54 4 22.22 11 15.76 5 22.74 12 13.68 6 22.26 13 14.1 7 20.78 14 14.02 8 17.6 15 11.94 9 16.52 16 12.76 Kuratidza mhinduro
\(y=-0.962x+26.86,r=-0.965\)
-
\(x\) \(y\) 4 44.8 5 43.1 6 38.8 7 39 8 38 9 32.7 10 30.1 11 29.3 12 27 13 25.8 -
\(x\) 21 25 30 31 40 50 \(y\) 17 11 2 –1 –18 –40 Kuratidza mhinduro
\(y=-\text{1}.\text{981}x+\text{6}0.\text{197;}\) \(r=-0.\text{998}\)
-
\(x\) \(y\) 100 2000 80 1798 60 1589 55 1580 40 1390 20 1202 -
\(x\) 900 988 1000 1010 1200 1205 \(y\) 70 80 82 84 105 108 Kuratidza mhinduro
\(y=0.\text{121}x-38.841,r=0.998\)
-
Graph \(f(x)=0.5x+10.\) Pick a set of five ordered pairs using inputs \(x=-2,\text{1},\text{5},\text{6},9\) and use linear regression to verify that the function is a good fit for the data.
-
Graph \(f(x)=-2x-10.\) Pick a set of five ordered pairs using inputs \(x=-2,\text{1},\text{5},\text{6},9\) and use linear regression to verify the function.
Kuratidza mhinduro
\((-2,-6),(1,\text{-12}),(5,-20),(6,\text{-22}),(9,\text{-28});\) Yes, the function is a good fit.
-
Use linear regression to determine a function \(P\) where the profit in thousands of dollars depends on the number of units sold in hundreds.
Symbols used here
Both signs at once: x = 3 ± 2 means 5 and 1.
The two sides are different.
Inequalities that allow equality; < and > exclude it.
The non-negative number whose square (n-th power) is x.
Distance from zero: |−3| = 3. For a complex number, distance from the origin.
i² = −1.
The exponent b must be raised to for x; ln uses base e.
Naturals, integers, rationals, reals, complex numbers.
How to: Fitting Linear Models to Data
- Draw and interpret scatter diagrams.
- Use a graphing utility to find the line of best fit.
- Distinguish between linear and nonlinear relations.
- Fit a regression line to a set of data and use the linear model to make predictions.
- Plot points in a rectangular coordinate system (IA 3.1.1).
- Find an equation of the line given two points (IA 3.3.3).
- Enter the input in List 1 (L1).
- Enter the output in List 2 (L2).
Questions people ask
What does it mean to solve an equation?
To find every value of the unknown that makes both sides equal. Each step is an operation applied to both sides that keeps the solution set the same, until the unknown stands alone.
Why do I sometimes get two answers?
A quadratic can cross the axis twice, so it can have two solutions. A degree-n polynomial has up to n. The graph shows where each one comes from.
How do I know whether to factor or use the quadratic formula?
Try factoring for a few seconds: look for two numbers that multiply to a·c and add to b. If nothing obvious appears, the discriminant b² − 4ac tells you how many real roots there are, and the formula finds them without guessing.
Tarisa yako
Parts of this page are adapted from OpenStax College Algebra 2e (CC BY-NC-SA 4.0). Condensed and re-explained here; errors are ours.
More in Algebra
Linear equationsQuadratic equationsSystems of equationsInequalitiesFactoringExpandingSimplifying expressionsFunctions and graphsExponential and logarithmic equationsPolynomial equationsAbsolute value