Linear Regression Calculator

  • Tested against OpenStax's example and 120 cases worked with exact fractions by an independent program
  • Checked by Wayne Bickerton
  • Sources: OpenStax
  • Updated November 6, 2026

Linear regression finds the straight line that best fits a set of paired numbers, like exam scores and study hours. Paste your x and y values to get the line of best fit, how strongly the two are linked (r and r²), a scatter plot and a prediction for any x. Everything updates as you type.

Same number of values in each list, in the same order. Separate them with commas, spaces or new lines. Type 1200, not 1,200.

Line of best fit
ŷ = 4.8274x − 173.5134 Positive correlation

On average, y goes up by 4.8274 for each 1 more in x. The line explains 43.97% of the variation in y (r² = 0.4397).

6575
Correlation (r) 0.6631
r² (share explained) 0.4397
ŷ when x is 73 178.8864

What is linear regression?

Linear regression finds the line of best fit: the straight line ŷ = a + bx that comes closest to all your points, in the sense that the squared vertical gaps between the points and the line add up to as little as possible. That is why it is also called the least-squares line.

The slope b says how much y changes, on average, for each 1 more in x. For the exam scores, each extra point on the third exam goes with 4.83 more points on the final, on average. Use the line only for x values inside your data: these scores run from 65 to 75, so predicting for 50 isn’t reliable.

Source OpenStax · Introductory Statistics 2e, 12.3 The Regression Equation ↗

How to calculate linear regression

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², then a = ȳ − b × x̄

Here it is with your numbers:

  1. There are 11 pairs.
  2. x̄ = 761 ÷ 11
  3. x̄ = 69.1818
  4. ȳ = 1,765 ÷ 11
  5. ȳ = 160.4545
  6. Σ(x − x̄)² = 81.6364
  7. Σ(x − x̄)(y − ȳ) = 394.0909
  8. b = 394.0909 ÷ 81.6364
  9. b = 4.8274
  10. a = ȳ − b × x̄
  11. a = −173.5134

It means the line ŷ = 4.8274x − 173.5134 predicts 178.8864 when x is 73.

What r and r² mean

The correlation coefficient r is always between −1 and 1. Close to 1 or −1 means the points sit close to a straight line; close to 0 means there is little straight-line link. Its sign matches the slope: positive when y rises with x, negative when it falls.

r², the coefficient of determination, is the share of the variation in y that the line explains. An r² of 0.4397 means the line explains about 44% of it; the other 56% is the scatter around the line. A strong correlation doesn’t mean x causes y.

Your points and the line

xyLine’s ŷ
65175140.2673
67133149.922
71185169.2316
71163169.2316
66126145.0947
75198188.5412
67153149.922
70163164.4042
71159169.2316
69151159.5768
69159159.5768

FAQs

What is the formula for linear regression?

The line is ŷ = a + bx, with slope b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and intercept a = ȳ − b × x̄, where x̄ and ȳ are the averages. For OpenStax’s exam scores the line is ŷ = −173.51 + 4.83x.

Source OpenStax · Introductory Statistics 2e, 12.3 The Regression Equation ↗

Is linear regression just y = mX + b?

Yes, the result is a straight line y = mx + b (statistics books often write ŷ = a + bx, with b the slope). What regression adds is how the line is chosen: it is the one with the smallest sum of squared errors, the vertical gaps between the points and the line.

How is R^2 calculated?

Square the correlation coefficient r. r = [nΣxy − ΣxΣy] ÷ √([nΣx² − (Σx)²][nΣy² − (Σy)²]). For the exam scores r is 0.6631, so r² is 0.4397: the line explains about 44% of the variation in final exam scores.

Does your line of best fit have to start at 0?

No. The line always passes through the point of averages (x̄, ȳ), and it crosses the y-axis wherever that puts it. For the exam scores it crosses at −173.51, far below 0.

How to do a line of best fit on TI-84?

Put the x values in L1 and the y values in L2 (STAT, EDIT). Then press STAT, choose TESTS, then LinRegTTest, set Xlist to L1 and Ylist to L2, and Calculate. The screen shows a and b for y = a + bx, with r² and r at the bottom.

Sources

Related calculators