← Statistics

Statistics

Linear Regression

Lesson

When two variables show a roughly linear relationship, the line of best fit (also called the regression line) is the line that comes closest to all the points. Once you have it, you can predict a value of yy from any xx.

y=mx+by = mx + b

The slope and intercept formulas:

m=nxyxynx2(x)2m = \frac{n\,\sum xy - \sum x \sum y}{n\,\sum x^2 - (\sum x)^2}
b=yˉmxˉb = \bar{y} - m\,\bar{x}

Where xˉ\bar{x} and yˉ\bar{y} are the means of the xx- and yy-values. Calculators and spreadsheets do this for you in practice; for small data sets it’s manageable by hand.

Once you have the line, prediction is just substitution — plug an xx value into y=mx+by = mx + b.

Worked example 1 — fit and predict

Data: (1, 5), (2, 8), (3, 11), (4, 14). The points jump by 3 each time, so the line is exactly y=3x+2y = 3x + 2: slope m=3m = 3, intercept b=2b = 2.

To predict yy at x=5x = 5:

y=3(5)+2=17y = 3(5) + 2 = 17

Worked example 2 — non-perfect data

Data: (1, 3), (2, 5), (3, 4), (4, 6). Using the formulas: xˉ=2.5, yˉ=4.5\bar{x} = 2.5,\ \bar{y} = 4.5, xy=49, x2=30\sum xy = 49,\ \sum x^2 = 30.

m=4(49)10(18)4(30)100=1620=0.8m = \frac{4(49) - 10(18)}{4(30) - 100} = \frac{16}{20} = 0.8
b=4.5(0.8)(2.5)=2.5b = 4.5 - (0.8)(2.5) = 2.5

Regression line: y=0.8x+2.5y = 0.8x + 2.5.

How to type your answer

A single number — slope, intercept, or a predicted yy value, depending on the question. Use a decimal point if needed. Examples: 3, 2.5, 17, -8.

Practice

Work through these. Stuck? Click Get a hint.

Warm-Up

Quick problems to get going.

Problem 1

Slope of regression line for (1,2), (2,4), (3,6), (4,8)\text{Slope of regression line for } (1,2),\ (2,4),\ (3,6),\ (4,8)

Problem 2

y-intercept of regression line for (1,2), (2,4), (3,6), (4,8)\text{y-intercept of regression line for } (1,2),\ (2,4),\ (3,6),\ (4,8)

Problem 3

Slope of regression line for (0,1), (1,3), (2,5), (3,7)\text{Slope of regression line for } (0,1),\ (1,3),\ (2,5),\ (3,7)

Problem 4

y-intercept of regression line for (0,1), (1,3), (2,5), (3,7)\text{y-intercept of regression line for } (0,1),\ (1,3),\ (2,5),\ (3,7)

Practice

Standard problems matching the lesson.

Problem 5

Slope for (1,5), (2,8), (3,11), (4,14)\text{Slope for } (1,5),\ (2,8),\ (3,11),\ (4,14)

Problem 6

y-intercept for (1,5), (2,8), (3,11), (4,14)\text{y-intercept for } (1,5),\ (2,8),\ (3,11),\ (4,14)

Problem 7

Slope for (1,10), (2,8), (3,6), (4,4)\text{Slope for } (1,10),\ (2,8),\ (3,6),\ (4,4)

Problem 8

y-intercept for (1,10), (2,8), (3,6), (4,4)\text{y-intercept for } (1,10),\ (2,8),\ (3,6),\ (4,4)

Problem 9

Using y=3x+2, predict y at x=5\text{Using } y = 3x + 2,\ \text{predict } y \text{ at } x = 5

Problem 10

Using y=2x+12, predict y at x=10\text{Using } y = -2x + 12,\ \text{predict } y \text{ at } x = 10

Problem 11

Using y=0.5x+3, predict y at x=8\text{Using } y = 0.5x + 3,\ \text{predict } y \text{ at } x = 8

Problem 12

Using y=1.5x+10, predict y at x=4\text{Using } y = -1.5x + 10,\ \text{predict } y \text{ at } x = 4

Problem 13

Slope for (2,5), (4,9), (6,13), (8,17)\text{Slope for } (2,5),\ (4,9),\ (6,13),\ (8,17)

Problem 14

y-intercept for (2,5), (4,9), (6,13), (8,17)\text{y-intercept for } (2,5),\ (4,9),\ (6,13),\ (8,17)

Challenge

Harder problems — edge cases, trickier numbers, multiple steps.

Problem 15

Using y=2.5x4, predict at x=12\text{Using } y = 2.5x - 4,\ \text{predict at } x = 12

Problem 16

Using y=3x+25, predict at x=7\text{Using } y = -3x + 25,\ \text{predict at } x = 7

Problem 17

Given m=4, b=7. Predict at x=6\text{Given } m=4,\ b=-7.\ \text{Predict at } x = 6

Problem 18

Given m=0.5, b=12. Predict at x=8\text{Given } m=-0.5,\ b=12.\ \text{Predict at } x = 8

Problem 19

Slope for (1,3), (2,5), (3,4), (4,6)\text{Slope for } (1,3),\ (2,5),\ (3,4),\ (4,6)

Problem 20

y-intercept for (1,3), (2,5), (3,4), (4,6)\text{y-intercept for } (1,3),\ (2,5),\ (3,4),\ (4,6)

Problem 21

Using y=0.8x+2.5, predict at x=10\text{Using } y = 0.8x + 2.5,\ \text{predict at } x = 10

Problem 22

Using y=0.8x+7, predict at x=5\text{Using } y = -0.8x + 7,\ \text{predict at } x = 5