Grade by Grade
D. Data · Data, Statistics and Mathematical Modelling

Lines of Best Fit, Linear Regression and Predictions

D1.3 A1About 70 minutes
Learning goals
  • I can draw a line of best fit by eye and find its equation.
  • I can use technology to find a linear regression equation and explain what the least-squares line is.
  • I can interpret the slope and y-intercept of a linear model in context.
  • I can find residuals and make predictions, and explain the difference between interpolation and extrapolation.

Words to know

line of best fit
A straight line that models the trend of the points on a scatter plot.
linear regression
A method, usually done with technology, for finding the line of best fit.
residual
The actual y-value minus the y-value predicted by the model.
least-squares line
The line that makes the sum of the squared residuals as small as possible.
slope
The rate of change of a line: rise ÷ run.
interpolation
Predicting a value within the range of the data.
extrapolation
Predicting a value outside the range of the data.

From a pattern to a prediction

Your phone shows 100% when you start streaming a movie. How long until it drops to 20%? If you recorded the battery level every 15 minutes, you could draw a line through the data and predict.

A line of best fit is a straight line that models the trend in a scatter plot. Once you have its equation, you can make predictions, and you can describe the relationship with numbers that have meaning in context.

Drawing a line of best fit by eye

  1. The line should follow the direction of the points.
  2. About the same number of points should be above and below the line, spread along its length.
  3. The line does not have to pass through any data point, and it does not have to start at the origin.
  4. Ignore an outlier that is clearly unusual, or note it.

To find its equation, pick two points on your line (not necessarily data points), find the slope, then find the y-intercept.

Remember: the equation of a line

A line can be written as y = mx + b.

  • m is the slope (rate of change): m = rise ÷ run = (y₂ − y₁) ÷ (x₂ − x₁).
  • b is the y-intercept: the value of y when x = 0.

You study linear relations in depth in the linear and non-linear relations unit of this course. Here we use them as models of data.

Worked example

Example 1: Equation of a line of best fit by eye

For the free-throw data from the last lesson, a student draws a line of best fit that passes through (40, 8) and (180, 18). Find its equation.

  1. Slope: m = (18 − 8) ÷ (180 − 40) = 10 ÷ 140 ≈ 0.071.
  2. Substitute (40, 8) into y = mx + b: 8 = 0.071 × 40 + b, so 8 = 2.84 + b and b ≈ 5.2.
  3. Equation: y ≈ 0.071x + 5.2.
  4. Meaning of the slope: each extra minute of practice per week is associated with about 0.071 more free throws made. That is about 0.7 more free throws for every 10 extra minutes.
  5. Meaning of the y-intercept: a player who did no practice is predicted to make about 5 free throws out of 20.

y ≈ 0.071x + 5.2. Different students drawing by eye will get slightly different lines; that is why we use technology for the "best" line.

Linear regression: the best line, found by technology

Technology finds the line of best fit using linear regression. For each data point, the vertical distance from the point to the line is called a residual:

residual = actual y − predicted y

A point above the line has a positive residual; a point below has a negative residual. The least-squares regression line is the line that makes the sum of the squares of all the residuals as small as possible. That gives one "best" line that everyone agrees on.

In Desmos, type y_1 ~ m x_1 + b. For the free-throw data, Desmos gives m ≈ 0.0737, b ≈ 4.98 and r ≈ 0.966, so the regression line is about y = 0.074x + 4.98.

Line of best fit (linear regression)0408012016020002468101214161820practice time per week (minutes)free throws made out of 20residual ≈ −0.9y = 0.074x + 4.98
The regression line passes through the middle of the points. The short vertical segment at 120 minutes is the residual for that player: the player made 13 free throws, but the line predicts about 13.9, so the residual is about 13 − 13.9 = −0.9.
Worked example

Example 2: Predicting with the regression line

Use y = 0.074x + 4.98 to predict the number of free throws made by a player who practises 110 minutes. Then predict for 400 minutes. Are the predictions reasonable?

  1. For x = 110: y = 0.074(110) + 4.98 = 8.14 + 4.98 = 13.12, so about 13 free throws.
  2. 110 is inside the range of the data (30 to 180). Predicting within the data is called interpolation. It is usually reliable when the correlation is strong.
  3. For x = 400: y = 0.074(400) + 4.98 = 29.6 + 4.98 = 34.58.
  4. But the test is out of 20! You cannot make 34.6 out of 20. Predicting beyond the data is called extrapolation, and the pattern may not continue.

About 13 free throws for 110 minutes (a reasonable interpolation). The prediction of 34.6 for 400 minutes is impossible, showing the danger of extrapolation: the linear model only works over a limited range.

MinutesBattery (%)
0100
1594
3087
4581
6073
7568
9062
10554
12049
Data for Example 3.
Worked example

Example 3: Phone battery

Maya streamed a video and recorded her phone's battery level:

(The data is in the table above.)

Technology gives y = −0.43x + 100.02 with r ≈ −0.999. Interpret the slope and intercept, then predict when the battery reaches 20%.

  1. Slope ≈ −0.43: the battery drops about 0.43 percentage points per minute, or about 26 points per hour (0.43 × 60 = 25.8).
  2. y-intercept ≈ 100: at 0 minutes the battery was full, which matches the data.
  3. r ≈ −0.999: an extremely strong negative linear relationship, so the model fits very well within the data.
  4. Use y ≈ −0.43x + 100. Set y = 20: 20 = −0.43x + 100, so −0.43x = −80 and x = 80 ÷ 0.43 ≈ 186 minutes.
  5. This is an extrapolation (beyond 120 minutes). Batteries do not always drain at a steady rate near the end, and screen brightness or other apps could change the rate.

About 186 minutes (just over 3 hours), assuming the battery keeps draining at the same rate. Because it is an extrapolation, treat it as an estimate.

Phone battery while streaming video04080120160200240020406080100minutes of video streamedbattery charge (%)extrapolation(beyond the data)interpolation(within the data)
The solid line is the regression line within the data (interpolation). The dashed part, in the shaded region, is an extrapolation: it assumes the pattern continues after 120 minutes.

Describe a linear model in context

A complete description of a linear model says:

  1. the equation (with the variables named),
  2. what the slope means (with units, "per minute", "per year"),
  3. what the y-intercept means (or why it has no sensible meaning),
  4. how well it fits (r, and a look at the scatter plot),
  5. the range of x-values where predictions are reasonable.
Just for fun

Why did the line of best fit go to therapy?

It was tired of everyone above it and below it calling it mean. (Strictly speaking, it is the least-squares line, but that didn't make it feel better.)

Hands-on activity

Stretchy spring scale

You need: a rubber band, a small zip-top bag, a ruler, tape, and 8 identical small items such as coins (loonies) or marbles. Ask a grown-up where you can tape the ruler (for example, the edge of a table).

  1. Tape the ruler vertically so it hangs down from the edge of a table. Hang the rubber band from the top of the ruler, and hang the bag from the rubber band.
  2. Record the position of the bottom of the bag with 0 items.
  3. Add one item at a time, up to 8, recording the position each time. Calculate the stretch (cm) for each number of items.
  4. Make a scatter plot (items on x, stretch on y). Draw a line of best fit by eye and find its equation.
  5. Use Desmos (y_1 ~ m x_1 + b) to find the regression line and r. Compare with your line.
  6. Predict the stretch for 5.5 items (interpolation) and for 30 items (extrapolation). Which prediction do you trust? Why?

What to look for: sensible data, a line with points on both sides, a correct slope calculation, and an explanation that the 30-item prediction is risky (the band could stop stretching evenly or snap).

Safety: keep your face away from the stretched band, and stop before it is close to snapping.

Your turn

1

A line of best fit passes through (2, 15) and (10, 55). Find its equation.

2

For the regression y = 0.074x + 4.98 (practice minutes, free throws), predict the free throws for 70 minutes.

3

A player practised 150 minutes and made 17 free throws. Find the residual using y = 0.074x + 4.98.

4

The data for a model covers x = 5 to x = 40. Is a prediction at x = 25 interpolation or extrapolation? At x = 60?

5

A regression for the price of pizza (y, dollars) and diameter (x, cm) is y = 0.55x − 2. Interpret the slope.

6

Using y = −0.43x + 100 for the phone battery, predict the battery after 50 minutes.

7

Why is the least-squares line called the "best" line?

More practice: warm-up

1

In y = mx + b, what does m represent?

2

Residual = ? − ?

3

A point lies below the line of best fit. Is its residual positive or negative?

4

Find y when x = 4 for y = 3x − 2.

5

True or false: a line of best fit must go through the origin.

More practice: on your own

1

Height (y, cm) is modelled from arm span (x, cm) for 8 students by y = 0.91x + 15. Predict the height of a student with an arm span of 160 cm, and explain whether the model makes sense at x = 0.

2

A line of best fit passes through (1995, 32) and (2015, 47), where y is the number of members of a curling club. Find the slope and interpret it.

3

A regression for snowfall predicts −12 cm of snow for a month. What does this tell you about the model?

4

Two students draw lines of best fit for the same data: y = 2.1x + 4 and y = 1.9x + 6. Who is right?

5

Using y = −0.43x + 100, when would the phone battery reach 0%? Why should you be careful with this answer?

Challenge

1

The points (1, 3), (2, 5), (3, 6), (4, 8) are modelled by y = 1.6x + 1.5. Find all four residuals and their sum. What do you notice?

2

A linear model for the winning time (s) in a 100 m race over many years has a negative slope. Explain why the model must eventually fail if you extrapolate far into the future.

3

A data set has r = 0.35. A student uses the regression line to make a prediction and says it is "very accurate". Respond.

Check your understanding

Quiz

1.

A line of best fit goes through (0, 12) and (5, 32). What is its equation?

2.

A point is (8, 20) and the line predicts 23 at x = 8. What is the residual?

3.

Data was collected for ages 10 to 16. Predicting the value at age 25 is an example of...

4.

The model y = 1.5x + 40 gives the cost (y, $) of a taxi ride of x km. What does 40 mean?

5.

What does the least-squares method minimize?

6.

Which statement about a line of best fit is true?

For parents and teachers

Big idea: D1.3 ends with "use a model to make predictions when appropriate". The key Grade 9 skills are interpreting slope and intercept in context and judging when a prediction is trustworthy.

How to help: Ask your teen to explain what the slope means in words with units ("0.43 percent per minute"). When they make a prediction, ask "Is that inside or outside the data? Do you trust it?"

Common difficulties:

  • Forcing the line through the origin or through the first and last points.
  • Mixing up the sign of a residual (it is actual minus predicted).
  • Accepting impossible extrapolations (34 out of 20, negative snowfall).

Safety: in the spring activity, stop adding weight before the rubber band is near breaking and keep faces clear.