3.2: Fitting Linear Models to Data (2024)

  1. Last updated
  2. Save as PDF
  • Page ID
    147258
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vectorC}[1]{\textbf{#1}}\)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}}\)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}}\)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}}}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{#1}}} \)

    Learning Objectives
    • Create and interpret scatter plots.
    • Fit a regression line to a set of data and use the linear model to make predictions.
    Prerequisite Skills

    Before you get started, take this prerequisite quiz.

    1. If \(y=-3.215x-78.2\), solve for \(y\) when \(x=-21\).

    Click here to check your answer

    \(y=-10.685\)

    If you missed this problem, review here. (Note that this will open a different textbook in a new window.)

    2. If \(y=-3.215x-78.2\), solve for \(x\) when \(y=-46.05\).

    Click here to check your answer

    \(x=-10\)

    If you missed this problem, review Section 1.1. (Note that this will open in a new window.)

    A professor is attempting to identify trends among final exam scores. His class has a mixture of students, so he wonders if there is any relationship between age and final exam scores. One way for him to analyze the scores is by creating a diagram that relates the age of each student to the exam score received. In this section, we will examine one such diagram known as a scatter plot.

    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. Figure \(\PageIndex{1}\) shows a sample scatter plot.

    3.2: Fitting Linear Models to Data (2)

    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.

    To create a scatter plot on Desmos
    1. Open your Desmos app, or go to https://www.desmos.com/calculator.
    2. Above the equation list, click the + icon.
    3. Click "table."
    4. Enter the x-values in the first column and the y-values in the second column.
    5. Click the magnifying glass to automatically adjust the viewing window to see the points. You can also manually adjust the window as necessary.
    Example \(\PageIndex{1}\): Using a Scatter Plot to Investigate Cricket Chirps

    The table below shows the number of cricket chirps in 15 seconds, for several different air temperatures, in degrees Fahrenheit. Plot this data and determine whether the data appears to be linearly related.

    Table \(\PageIndex{1}\)
    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 Figure \(\PageIndex{2}\) 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.

    3.2: Fitting Linear Models to Data (3)

    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 \(\PageIndex{2}\): "Eyeballing" a Line of Best Fit

    Find a linear function that fits the data in Table \(\PageIndex{1}\) 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=\dfrac{60}{50}=1.2\nonumber\]

    and a y-intercept at 30. This gives an equation of

    \[T(c)=1.2c+30\nonumber\]

    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 Figure \(\PageIndex{3}\).

    3.2: Fitting Linear Models to Data (4)

    Analysis

    This linear equation can then be used to approximate answers to various questions we might ask about the trend.

    Exercise \(\PageIndex{1}\)

    According to the data from Table \(\PageIndex{1}\), what temperature can we predict it is if we counted 29 chirps in 15 seconds?

    Solution

    According to the line the temperature would be somewhere in the low 60s, approximately 63°F.

    Finding the Line of Best Fit Using a Graphing Program

    While eyeballing a line works reasonably well, some statistical techniques exist for fitting a line to data that minimize the differences between the line and data values[2]. One such technique is called least squares regression and can be computed by many graphing calculators, spreadsheet software, statistical software, and many web-based calculators[3]. 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.

    To find a line of best fit using Desmos
    1. Open your Desmos app, or go to https://www.desmos.com/calculator.
    2. Create a scatter plot, as listed above.
    3. After the xy table, in the space for the next equation, write \(y_1\)~\(mx_1+b\). This tells the program to use the values of \(x_1\) and \(y_1\) from the table above.
      • The ~ sign tells the program to approximate the equation, since a linear equation won't fit the data precisely.
      • The \(x_1\) and \(y_1\) tell the program to use the values of \(x_1\) and \(y_1\) from the table above.
      • The \(m\) and \(b\) represent slope and y-intercept of the line, respectively.
    4. Press Enter.
    5. The resulting information will display the appropriate slope (\(m\)) and y-intercept (\(b\)) values of the line of best fit.
      • The information will also display statistics of \(r^2\) and \(r\). An r-value of 1 will indicate an exact fit. The closer the r-value is to 1, the closer the data fits the line of best fit.
    6. For a video explanation of this process, click HERE. The first 53 seconds show how to enter a scatter plot. The line of best fit begins at the 0:53 mark.
      Example \(\PageIndex{3}\): Finding a Linear Regression Equation

      Find the line of best fit using the cricket-chirp data in Table \(\PageIndex{1}\).

      Solution

      Table \(\PageIndex{1}\)
      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

      Enter the input (chirps) in \(x_1\). Enter the output (temperature) in \(y_1\).

      Enter \(y_1~mx_1+b\) in the next equation space.

      Note the m and b values for the data.

      Therefore we obtain the equation:

      \[y=1.143x+30.281 \nonumber \]

      or

      \[T=1.143c+30.281 \nonumber \]

      3.2: Fitting Linear Models to Data (5)

      3.2: Fitting Linear Models to Data (6) Will there ever be a case where two different lines will serve as the best fit for the data?

      No. There is only one best fit line.

      Predicting with a Regression Line

      Once we determine that a set of data is linear, 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 \(\PageIndex{4}\): Using a Regression Line to Make Predictions

      Gasoline consumption in the United States has been steadily increasing. Consumption data from 1994 to 2004 is shown in Table \(\PageIndex{3}\).

      a. Graph the data and determine whether the trend is linear. If so, find a model for the data.

      b. Use the model to predict the consumption in 2008.

      c. Use the model to predict when oil consumption would reach 160 billion gallons.

      Table \(\PageIndex{3}\)
      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

      a. The scatter plot of the data, including the least squares regression line, is shown in Figure \(\PageIndex{5}\).

      3.2: Fitting Linear Models to Data (7)

      We can introduce new input variable, \(t\),representing years since 1994.

      The linear regression equation is:

      \[C=113.318+2.209t \nonumber \]

      b. Using this to predict consumption in 2008, set \(t=14\).

      \[\begin{align*} C&=113.318+2.209(14) \\ &=144.244 \end{align*} \]

      The model predicts 144.244 billion gallons of gasoline consumption in 2008.

      c. Using the model to predict time when consumption is 160 billion gallons, set \(C=160\).

      \[\begin{align*} 160&=113.318+2.209(t) \\ 46.682&=2.209(t) \\ 21.133 &=t \end{align*} \]

      21 years after 1994 is the year 2015, so oil consumption is expected to reach 160 billion gallons in 2015.

      Exercise \(\PageIndex{2}\)

      Use the model we created using technology in Example \(\PageIndex{4}\) to predict the gas consumption in 2011.

      Answer

      150.871 billion gallons

      Key Concepts

      • Scatter plots show the relationship between two sets of data.
      • 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.
      • The correlation coefficient, \(r\), indicates the degree of linear relationship between data.
      • A regression line best fits the data.
      • The least squares regression line may be used to make predictions regarding either of the variables.

      Contributors and Attributions

      3.2: Fitting Linear Models to Data (2024)

      References

      Top Articles
      Latest Posts
      Article information

      Author: Allyn Kozey

      Last Updated:

      Views: 5945

      Rating: 4.2 / 5 (63 voted)

      Reviews: 86% of readers found this page helpful

      Author information

      Name: Allyn Kozey

      Birthday: 1993-12-21

      Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

      Phone: +2456904400762

      Job: Investor Administrator

      Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

      Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.