Steply

Find the least-squares regression line for predicting y from x

Step by step, with the reason for every step · AP Statistics Practice Exam 2 · AP Statistics

Step by step

The question

Question: find the line of best fit for (20, 30), (22, 35), (24, 37), (26, 43), (28, 45).

(20, 30) (22, 35) (24, 37) (26, 43) (28, 45)

The line of best fit is the straight line that comes closest to all the points.

best fit: the line closest to all the points

1 Find the means

The mean of the x numbers: 120 divided by 5 is 24.

mean x = 20 + 22 + 24 + 26 + 285 = 1205 = 24

The mean of the y numbers: 190 divided by 5 is 38.

mean y = 30 + 35 + 37 + 43 + 455 = 1905 = 38

The line of best fit always goes through the mean point, (24, 38).

the line goes through (24, 38)

2 Make the table

A table with the points.

Each x minus the mean x, 24.

Each y minus the mean y, 38.

For the first point: 20 minus 24 is −4, and 30 minus 38 is −8.

The product: the two distances multiplied.

−4 times −8 is 32.

And the x distance squared.

−4 squared is 16.

We add the last two columns: 76 and 40.

3 Find the slope

A line is y = m x + b.

The slope m is how much y goes up when x goes up by 1.

The products show how y moves with x.

The squares show how x moves by itself.

So the slope is the total of the products, over the total of the squares.

m = total of productstotal of squares

Careful!

The bottom uses only the x distances, squared.

Not the y distances.

Careful: the bottom is the x distances squared

76/40 is 1.9.

m = 7640 = 1.9

4 Find b

b is where the line crosses the y axis.

The line goes through the mean point.

So the mean y is m times the mean x, plus b.

mean y = m × mean x + b

To get b alone, we take m times the mean x away from both sides.

b = mean y − m × mean x

1.9 times 24 is 45.6.

38 minus 45.6 is −7.6.

b = 38 − 1.9 × 24 = 38 − 45.6 = −7.6

So the line of best fit is y = 1.9x − 7.6.

y = 1.9x − 7.6

5 Draw the line

Now the points on a graph.

Each point is a dot.

The line goes through the mean point.

The line y = 1.9x − 7.6: it passes close to all the points.

6 Check

Let's check: the mean point must be on the line.

1.9 times 24 plus −7.6 is 38.

That is the mean y.

So it is right!

1.9 × 24 + (−7.6) = 38

Let's look back.

First: find the means.

Then: make the table.

Then: find the slope.

Then: find b.

Then: draw the line.

Last: check.

Answer
y = 1.9x − 7.6

Your turn

Try this one yourself, then check your answer:

Best-fit line: (20, 32) (22, 33) (24, 37) (26, 45) (28, 43)
Show the answer
y = 1.7x − 2.8

More from AP Statistics Practice Exam 2

The whole lesson: AP Statistics Practice Exam 2 →