Menu
Sign up Sign in

AI SL · 13.3

Statistics

13.3.7

Linear regression and prediction

13.3.7

Linear regression and prediction

Target: I can find the equation of the regression line of y on x with the calculator. (+6 more)

By the end of this section

Key points

The regression line of y on x

  • The regression line \(y=ax+b\) is the least-squares line: it makes the total of the squared vertical distances to the points as small as possible.
  • It passes through the mean point \((\bar{x},\bar{y})\). Find a and b with the calculator and give them to 3 significant figures.
  • Use the line of y on x to predict y from x. Do not use it to predict x from y. The line makes the vertical distances small, so a value of x found by solving it for x is not reliable.
  • Quote r as well. The closer |r| is to 1, the more closely the points follow the line.
  • Because the line passes through the mean point, \(\bar{y}=a\bar{x}+b\). Use this to find a missing mean.

Interpreting the line

  • Gradient a: when x increases by 1 unit, y changes by a units on average. Give the units of y and say "on average".
  • Intercept b: the value of y when x = 0. If x = 0 is outside the range of the data, it is only a modelled value and may not make sense.
  • A negative gradient means y falls as x rises. Say "falls", not "rises by a negative number".

Predicting and reliability

  • To predict, put the x value into the line. Use the stored line, not rounded a and b.
  • Interpolation: x inside the range of the data. This is reliable if |r| is strong.
  • Extrapolation: x outside the range. The pattern may not continue, so the prediction is unreliable. Say that it is outside the range.
  • If the points bend, one line is a poor model. Split the data and fit a line to each part, then predict with the line for the part that contains x.

Outliers

  • Test one variable at a time: a value is an outlier if it is below \(Q_1-1.5\times IQR\) or above \(Q_3+1.5\times IQR\). Find Q₁ and Q₃ with the calculator.
  • A bivariate outlier breaks the pattern of the scatter diagram. Its x and y values may each be ordinary: the odd thing is the pair.
  • Outliers move the regression line and weaken r. Find the line with and without the outlier and compare.
  • Check an outlier before you remove it. It may be a mistake, or it may be real.

On the calculator

The regression line

  • Enter the x values and the y values in two lists.
  • Run linear regression (mx+b) with the x list and the y list.
  • Read a (the calculator's m), b and r. Store the line as a function so you can use it to predict.

Screenshot and video to come

Predicting from the stored line

  • Evaluate the stored function at the x value.
  • Do not round a and b first: use the stored line.

Screenshot and video to come

Quartiles for the outlier test

  • Run one-variable statistics on the x list, then on the y list.
  • Read Q1 and Q3 for each, then work out the limits Q1 − 1.5 × IQR and Q3 + 1.5 × IQR.

Screenshot and video to come

Spotting a bivariate outlier

  • Plot the scatter diagram with the regression line.
  • Look for a point that is far from the line while its x and y values are ordinary.

Screenshot and video to come

Regression with and without a point

  • Run the regression on all the points and note a, b and r.
  • Delete the point from both lists (keep a copy), run the regression again and compare.

Screenshot and video to come

A model in two parts

  • Put each part of the data into its own pair of lists.
  • Run linear regression on each part and note both lines.
  • Use the line for the part that contains the x value you are predicting for.

Screenshot and video to come

Explore: what "least squares" means

Drag the two orange handles to place a line among the points. Each residual is a vertical segment, and its square is drawn beside it. Make the squares add up to as little as you can.

SSres =

Sum of the squares

Your line
Least squares line
Smallest possible sum

Drag a handle.

  1. Move the line so that one square gets smaller. What happens to the squares of the other points? Can you make every square small at once?
  2. Why are the residuals squared before they are added? What would go wrong if you added the residuals themselves?
  3. Press "Show the least squares line". Move one handle a little in either direction. Why does the sum go up both ways?
  4. Choose "Odd point". Where does the least squares line go, and why does the odd point have so much pull on it?

Explore: correlation and the regression line

Drag the black points and watch r and the line. Drag the orange point along the x-axis to predict y from x.

Mean point (x̄, ȳ)
Pearson's r
Correlation
Total of the squared residuals

Drag a point.

  1. Drag one point a long way from the others. What happens to r? What happens to the line?
  2. Does the regression line always pass through the mean point? Try three different patterns.
  3. Tick "Show the residuals" and drag a point. The line always moves to make the total of the squared residuals as small as it can. Why can no other straight line have a smaller total?
  4. Press "A curve". The points follow a clear pattern, but r is close to 0. What does r measure, and what does it not measure?
  5. Drag the orange point outside the range of the data. Why is the prediction less reliable there?

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
Finding the regression line

A letting agent records the distance x (km) of 8 flats from the city centre and the monthly rent y (€). x: 1.5, 2.8, 3.4, 4.9, 6.1, 7.3, 8.6, 9.8 y: 1480, 1330, 1290, 1110, 1040, 900, 830, 720 Find the equation of the regression line of y on x.

123456789101120040060080010001200140016001800x (km)y (€)
Working
  1. Enter the data

    List x: 1.5, 2.8, 3.4, 4.9, 6.1, 7.3, 8.6, 9.8; list y: 1480, 1330, 1290, 1110, 1040, 900, 830, 720

    Distance is the x variable. Rent is the y variable we want to predict.

  2. Linear regression

    From the calculator: \(a=-90.5\), \(b=1590\), \(r=-0.996\)

    Use linear regression (mx+b) with the x list and the y list. The calculator's m is our a.

  3. Write the equation

    \(y=-90.5x+1590\)

    Give the line as an equation in x and y, with a and b to 3 significant figures. The line passes through the mean point.

Video walkthrough coming
What the gradient and intercept mean

A cinema records the ticket price x (€) and the number of people y at the 8 p.m. showing on 15 evenings. The prices ranged from €6 to €15. The regression line of y on x is \(y=212-9.4x\). (a) Interpret the gradient. (b) Interpret the intercept.

Working
  1. Gradient

    The gradient is −9.4

    For each €1 increase in the ticket price, the number of people falls by 9.4 on average. Say "on average", and give units.

  2. Intercept

    The intercept is 212

    When the ticket price is €0, the model gives 212 people.

  3. Take care

    x = 0 is outside the range €6 to €15

    Free tickets were never tried, so 212 is a value the model gives, not one the data support. Say so if the question asks whether it is sensible.

Video walkthrough coming
Predicting, and when to trust it

A teacher finds a regression line of y on x for the weekly revision time x (hours) and the test score y (out of 100) of 40 students. The times ranged from 4 to 20 hours, and r = 0.88. The line is \(y=3.1x+35.6\). (a) Predict the score of a student who revises for 12 hours. (b) Predict the score for 30 hours. Comment on the reliability of each prediction.

Working
  1. Substitute x = 12

    \(y=3.1\times12+35.6=72.8\)

    Put the x value into the line.

  2. Is it reliable?

    12 is inside the range 4 to 20: interpolation

    The prediction is reliable because x is inside the data range and r = 0.88 is strong.

  3. Substitute x = 30

    \(y=3.1\times30+35.6=129\)

    A score above 100 is impossible.

  4. Comment

    30 is outside the range 4 to 20: extrapolation

    The line may not continue beyond the data. This prediction is not reliable.

Video walkthrough coming
The mean point and the line of y on x

A farmer records the amount of fertiliser x (g per plant) and the yield y (kg) of 25 plants. The regression line of y on x is \(y=0.36x+2.1\). The mean amount of fertiliser was 40 g per plant. The amounts ranged from 15 g to 55 g. (a) Find the mean yield. (b) The farmer wants a yield of 20 kg and solves \(20=0.36x+2.1\) for x. Explain why this is not a reliable use of the line.

Working
  1. The mean point is on the line

    \(\bar{y}=0.36\bar{x}+2.1\)

    The regression line always passes through \((\bar{x},\bar{y})\).

  2. Mean yield

    \(\bar{y}=0.36(40)+2.1=16.5\) kg

    Put in the mean amount of fertiliser.

  3. Solving for x

    \(x=\frac{20-2.1}{0.36}=49.7\) g

    This is the value the farmer would get.

  4. Why it is not reliable

    The line of y on x predicts y from x, not x from y

    It makes the vertical distances small, so it is for estimating the yield from the fertiliser. Solving it for x does not give a reliable amount of fertiliser.

Video walkthrough coming
Testing each variable for outliers

The stem length x (cm) and the mass y (g) of 11 seedlings are: x: 9, 12, 14, 15, 17, 18, 20, 21, 23, 25, 28 y: 31, 38, 36, 44, 41, 47, 45, 52, 49, 118, 57 Use the 1.5 × IQR rule to test x and y for outliers.

Working
  1. Quartiles of x

    From the calculator: \(Q_1=14\), \(Q_3=23\), IQR = 9

    One-variable statistics on the x list.

  2. Limits for x

    Lower: \(14-1.5\times9=0.5\); upper: \(23+1.5\times9=36.5\)

    All x values lie between 0.5 and 36.5: no outlier in x.

  3. Quartiles of y

    \(Q_1=38\), \(Q_3=52\), IQR = 14

    One-variable statistics on the y list.

  4. Limits for y

    Lower: \(17\); upper: \(52+1.5\times14=73\)

    Outliers lie outside the limits.

  5. State

    The mass 118 g is above 73: an outlier in y. There is no outlier in x.

    The seedling with x = 25 and y = 118 is the one to check.

Video walkthrough coming
A point that breaks the pattern

The age x (years) and the value y (€ thousand) of 10 cars of one model are: x: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 y: 24.5, 21.4, 20.8, 17.6, 6.5, 14.5, 12.9, 9.2, 8.9, 5.6 (a) Plot the data and identify any outlier. (b) Find the regression line and r with and without the outlier. (c) Describe the effect of the outlier.

1234567891011481216202428x (years)y (€ thousand)outlier
Working
  1. Plot and look

    The point (5, 6.5) is far below the pattern of the others

    Its x value and its y value are both ordinary. It is odd only because of the pair.

  2. Test x and y separately

    x: limits −4.5 and 15.5; y: limits −8.95 and 38.7

    Every x and every y lies inside its limits. Neither variable has an outlier alone: (5, 6.5) is a bivariate outlier.

  3. With the outlier

    \(y=-1.95x+24.9\), \(r=-0.884\)

    Linear regression on all 10 points.

  4. Without the outlier

    \(y=-2.01x+26.2\), \(r=-0.994\)

    Delete the point from both lists and run the regression again. In the diagram the teal line uses all 10 points and the orange line leaves out the outlier.

  5. Compare

    The gradient changes from −1.95 to −2.01; |r| rises from 0.884 to 0.994

    One point makes the line flatter and the correlation weaker. Check the point (a mistake?), but do not delete it just because it is awkward.

Video walkthrough coming
A model in two parts

A phone battery charges. The charge y (%) after x minutes is: x: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 y: 5, 22, 38, 54, 69, 76, 80, 84, 86, 91 (a) Plot the data. Explain why one line is not a good model. (b) Find a line for each part and use it to predict the charge after 75 minutes.

102030405060708090100102030405060708090100x (minutes)y (%)
Working
  1. Plot

    Steep to 40 minutes, then gentle

    The points bend. One line would fit neither part well.

  2. Split the data

    Part 1: x = 0 to 40. Part 2: x = 50 to 90.

    Use the two lists separately.

  3. Two regressions

    Part 1: \(y=1.6x+5.6\). Part 2: \(y=0.36x+58.2\)

    Linear regression on each list.

  4. Predict

    x = 75 is in part 2: \(y=0.36\times75+58.2=85.2\)

    Choose the line for the region that contains x. The charge is about 85.2%.

Video walkthrough coming