maths.freePrecalculus › 2. Linear Functions › Fitting Linear Models to Data

Fitting Linear Models to Data

Draw and interpret scatter plots.

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.

Chirps443520.433313518.53726
Temperature80.570.5576668725273.553
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

\[m=\frac{60}{50}=1.2\]

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
  1. Enter the input (chirps) in List 1 (L1).
  2. Enter the output (temperature) in List 2 (L2). See .
    L1443520.433313518.53726
    L280.570.5576668725273.553
  3. On a graphing utility, select Linear Regression (LinReg). Using the cricket chirp data from earlier, with technology we obtain the equation: \[T(c)=30.281+1.143c\]

Condensed — the full section is in OpenStax Precalculus 2e.

Distinguishing Between Linear and Non-Linear 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.

Predicting with a Regression Line

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)113116118119123125126128131133136

The scatter plot of the data, including the least squares regression line, is shown in .

Solution

We can introduce 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 .

Practice (40)

Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.

  1. 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.

    Chirps443520.433313518.53726
    Temperature80.570.5576668725273.553
    Paljasta vastaus

    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.

  2. Find a linear function that fits the data in by “eyeballing” a line that seems to fit.

    Paljasta vastaus

    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

    \[m=\frac{60}{50}=1.2\]

    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 .

  3. Use the cricket data from to answer the following questions:

    1. ⓐ 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.
    2. ⓑ 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.
    Paljasta vastaus
    1. ⓐ 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}{l}T(30)=30+1.2(30) \\ =66\ \text{degrees}\end{array}\]
      Based on the data we have, this value seems reasonable.
    2. ⓑ 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 .

  4. According to the data from , what temperature can we predict it is if we counted 20 chirps in 15 seconds?

    Paljasta vastaus

    \(54^{\circ}\text{F}\)

  5. Find the least squares regression line using the cricket-chirp data in .

    Paljasta vastaus
    1. Enter the input (chirps) in List 1 (L1).
    2. Enter the output (temperature) in List 2 (L2). See .
      L1443520.433313518.53726
      L280.570.5576668725273.553
    3. On a graphing utility, select Linear Regression (LinReg). Using the cricket chirp data from earlier, with technology we obtain the equation: \[T(c)=30.281+1.143c\]
  6. Calculate the correlation coefficient for cricket-chirp data in .

    Paljasta vastaus

    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.

  7. 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)113116118119123125126128131133136

    The scatter plot of the data, including the least squares regression line, is shown in .

    Paljasta vastaus

    We can introduce 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.

  8. Use the model we created using technology in to predict the gas consumption in 2011. Is this an interpolation or an extrapolation?

    Paljasta vastaus

    150.871 billion gallons; extrapolation

  9. Describe what it means if there is a model breakdown when using a linear model.

    Paljasta vastaus

    When our model no longer applies, after some value in the domain, the model itself doesn’t hold.

  10. What is interpolation when using a linear model?

  11. What is extrapolation when using a linear model?

    Paljasta vastaus

    We predict a value outside the domain and range of the data.

  12. Explain the difference between a positive and a negative correlation coefficient.

  13. Explain how to interpret the absolute value of a correlation coefficient.

    Paljasta vastaus

    The closer the number is to 1, the less scattered the data, the closer the number is to 0, the more scattered the data.

  14. 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}\]
  15. 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}\]
    Paljasta vastaus

    61.966 years

  16. 0246810
    –22–19–15–11–6–2
  17. 123456
    46505975100136
    Paljasta vastaus

    No.

  18. 100250300450600750
    1212.613.11414.515.2
  19. 1357911
    192865125216
    Paljasta vastaus

    No.

  20. 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.

    YearPopulation
    199011,500
    199512,100
    200012,700
    200513,000
    201013,750
  21. 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, °F1618202530
    Time, seconds4650545562
    Paljasta vastaus

    Interpolation. About \(60^{\circ}\text{ F}.\)

  22. \(r=0.\text{95}\)

  23. \(r=-0.\text{89}\)

    Paljasta vastaus

    C

  24. \(r=0.26\)

  25. \(r=-0.39\)

    Paljasta vastaus

    B

  26. 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 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%?

    YearPercent Graduates
    199021.3
    199221.4
    199422.2
    199623.6
    199824.4
    200025.6
    200226.7
    200427.7
    200628
    200829.4
  27. 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?

    YearImports
    19922665
    19942688
    19963565
    19984129
    20004584
    20025655
    20046549
    20067950
    20088487
    20099462
    Paljasta vastaus

    Yes, trend appears linear because \(r=0.\text{985}\) and will exceed 12,000 near midyear, 2016, 24.6 years since 1992.

  28. 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?

    YearNumber Unemployed
    1990750
    1992670
    1994650
    1996605
    1998550
    2000510
    2002460
    2004420
    2006380
    2008320
  29. \(x\) 815263156
    \(y\) 23415372103
    Paljasta vastaus

    \(y=\text{1}.\text{64}0x+\text{13}.\text{8}00\), \(r=0.\text{987}\)

  30. \(x\) 57101215
    \(y\) 412172224
  31. \(x\) \(y\) \(x\) \(y\)
    321.91115.76
    422.221213.68
    522.741314.1
    622.261414.02
    720.781511.94
    817.61612.76
    916.521711.28
    1018.54189.1
    Paljasta vastaus

    \(y=-0.962x+26.86,\ r=-0.965\)

  32. \(x\) \(y\)
    444.8
    543.1
    638.8
    739
    838
    932.7
    1030.1
    1129.3
    1227
    1325.8
  33. \(x\) 212530314050
    \(y\) 17112-1-18-40
    Paljasta vastaus

    \(y=-\text{1}.\text{981}x+\text{6}0.\text{197}\); \(r=-0.\text{998}\)

  34. \(x\) 1008060554020
    \(y\) 200017981589158013901202
  35. \(x\) 9009881000101012001205
    \(y\) 70808284105108
    Paljasta vastaus

    \(y=0.\text{121}x-38.841,\ r=0.998\)

  36. Graph \(f(x)=0.5x+10\). Pick a set of 5 ordered pairs using inputs \(x=\text{-2},\text{ 1},\text{ 5},\text{ 6},\text{ 9}\) and use linear regression to verify that the function is a good fit for the data.

  37. Graph \(f(x)=-2x-10\). Pick a set of 5 ordered pairs using inputs \(x=\text{-2},\text{ 1},\text{ 5},\text{ 6},\text{ 9}\) and use linear regression to verify the function.

    Paljasta vastaus

    \((\text{-2},-6),(\text{1},\text{-12}),(\text{5},\text{-2}0),(\text{6},\text{-22}),(\text{9},\text{-28})\); \(y=-2x-10\)

  38. Use linear regression to determine a function \(P\) where the profit in thousands of dollars depends on the number of units sold in hundreds.

  39. Find to the nearest tenth and interpret the x-intercept.

    Paljasta vastaus

    \((\text{189}.\text{8},0)\\) If 18,980 units are sold, the company will have a profit of zero dollars.

  40. Find to the nearest tenth and interpret the y-intercept.

Symbols used here

|x|
absolute value / modulus
Distance from zero: |−3| = 3. For a complex number, distance from the origin.
\binom{n}{k}
binomial coefficient, "n choose k"
Number of k-element subsets of n things: n!/(k!(n−k)!).
\pi
pi
Ratio of a circle's circumference to its diameter, 3.14159…
e
Euler's number
2.71828…, the base whose exponential is its own derivative.
i
imaginary unit
i² = −1.
\theta
theta
The usual name for an angle.
\log_b x,\ \ln x
logarithm, natural log
The exponent b must be raised to for x; ln uses base e.
\mathbf{v},\ \vec{v}
vector
A quantity with magnitude and direction; a column of numbers.

How to: Fitting Linear Models to Data

  1. Draw and interpret scatter plots.
  2. Find the line of best fit.
  3. Distinguish between linear and nonlinear relations.
  4. Use a linear model to make predictions.
  5. The method of
  6. The method of
  7. Enter the input in List 1 (
  8. Enter the output in List 2 (

Questions people ask

What is a function, really?

A rule that assigns exactly one output to each input. The vertical-line test on a graph is the same idea: no input may have two outputs.

Why do we need complex numbers?

Because x² + 1 = 0 has no real solution, and allowing one new number i with i² = −1 makes every polynomial equation solvable. They then turn out to describe rotation, waves and alternating current more naturally than real numbers do.

Kokeile omaasi

Parts of this page are adapted from OpenStax Precalculus 2e (CC BY-NC-SA 4.0). Condensed and re-explained here; errors are ours.

Lisää Precalculus