ViewWiki

Lesson 5 of 5

The line of best fit.

About 25 minutes · 5 practice questions

Which straight line fits a cloud of points best? Turn a line by hand until the squares add up to the least, and discover least squares, the balance point, predicting from the line, and what an outlier does to it.

Step 1 of 5 · By hand

Step 1 of 5

By hand

A correlation says how strong a link is. Sometimes you want more: a line that predicts yy⁠ for any xx⁠. In the linear functions Unit you met the line y=a+bxy = a + bx⁠, with slope bb⁠ and intercept aa⁠. Which such line fits the points best?

Every line misses every point by some vertical distance, its residual. On the board each residual is a stick from the bead to the line, with a square on each stick. The best line is the one whose squares add up to the least: the line of best fit, by least squares. Squares and not plain distances, for the same reason as in the standard deviation: distances above and below would cancel.

Your line turns about (xˉ,yˉ)(\bar{x}, \bar{y})⁠, and the coloured square under the plot is the average square about it, se2s_e^2⁠. The chart beside the Scene shows the squares’ area for every slope. Find the best line.

To the question

Step 2 of 5

The balance point

The board now turns your line to the exact line of best fit and prints it: y^=1.90+0.62x\hat{y} = 1.90 + 0.62x⁠. The hat on y^\hat{y}⁠ means “predicted value”, as against a value that was measured.

The slope of the line of best fit is

b=∑(x−xˉ)(y−yˉ)∑(x−xˉ)2b = \frac{\sum (x - \bar{x})(y - \bar{y})}{\sum (x - \bar{x})^2}⁠

But first, a question about the point the line turned about.

To the question

Step 3 of 5

Predicting

This is what the line is for: predicting yy⁠ at an xx⁠ that was not measured exactly. Put the xx⁠ into the equation.

A prediction inside the range of the readings, here between 11⁠ and 99⁠, is called interpolation, and it is reasonable. A prediction far outside it, extrapolation, is risky: no reading tells you the link stays a straight line out there.

To the question

Step 4 of 5

One far point

In the Lesson on averages you saw that an outlier pulls the mean and leaves the median nearly where it was. The line of best fit is built from squares, so it behaves like the mean, not the median.

To the question

Step 5 of 5

How much the line explains

The board also prints r2=1−se2s2r^2 = 1 - \frac{s_e^2}{s^2}⁠. The two squares under the plot compare the average square about the mean, s2s^2⁠, with the average square about the line, se2s_e^2⁠. r2r^2⁠ is the share of the scatter in yy⁠ the line accounts for, and 1−r21 - r^2⁠ the share left over as noise. Here r2=0.78r^2 = 0.78⁠: the line accounts for 78%78\%⁠ of the scatter.

Move Noise and watch the two squares close up or draw apart. To finish, work out r2r^2⁠ for a real study.

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Reach the target

Your line passes through (xˉ,yˉ)(\bar{x}, \bar{y})⁠. Change Slope of your line until the squares’ area is at most 5%5\%⁠ above the least possible, then press Check.

To the experiment

Practice · Choose

Which point does the line of best fit always pass through, whatever the cloud of points?

To the experiment

Practice · Calculate

The board prints the line of best fit, y^=a+bx\hat{y} = a + bx⁠. By it, what is the predicted value of yy⁠ at x=8x = 8⁠? Round to two decimal places.

To the experiment

Practice · Predict, then look

Switch on Outlier: one reading on the right, far below the rest. What happens to the slope of the line of best fit, now 0.620.62⁠?

To the experiment

Practice · Calculate

A study finds r=0.8r = 0.8⁠ between hours of study and marks. What per cent of the scatter in the marks (of the squares’ area about the mean) does the line of best fit account for? Write the number only.