Linear Regression Calculator

Find the least-squares regression line ŷ = a + bx from paired data, with the slope, intercept, correlation r and r², a scatter plot with residuals, and predictions for any x.

Line of best fit
ŷ = 47.0357 + 4.381x
Slope b
4.381
Intercept a
47.0357
r
0.9942
r²
0.9885
ŷ = 86.4643
Dots are your data, the blue line is the least-squares fit, and red dashes are residuals (actual − predicted).

Step-by-step working

  1. Means of x and yx̄ = 4.5, ȳ = 66.75
  2. Sums of squares and cross-productsSxx = Σ(x − x̄)² = 42 Syy = Σ(y − ȳ)² = 815.5 Sxy = Σ(x − x̄)(y − ȳ) = 184
  3. Slope b = Sxy ÷ Sxxb = 184 ÷ 42 = 4.381
  4. Intercept a = ȳ − b·x̄a = 66.75 − 4.381 × 4.5 = 47.0357
  5. Regression lineŷ = 47.0357 + 4.381x
  6. Correlation and fitr = 0.9942, r² = 0.9885

Formula b = Sxy ÷ Sxx a = ȳ − b·x̄ r² = Sxy² ÷ (Sxx · Syy)

Ask the tutor about your result

An AI tutor reads your inputs and results above and explains them in plain English. The numbers come from the calculator; the explanation is AI-written, so check it against your notes.

Drag the points: how least squares picks the line

Drag any point up or down (or focus it and use ↑ ↓). The least-squares line is the one line that makes the total area of the residual squares as small as possible. Pull one point far away and watch it tilt the whole line.

ŷ = 1.16 + 0.92x · r = 0.976 · total squared residuals = 1.16

Why squares? Squaring makes every miss positive and punishes big misses much more than small ones, and it gives a single, exact solution (the formulas b = Sxy ÷ Sxx, a = ȳ − b·x̄). That’s also why one outlier can have so much pull.

Interpreting slope and intercept

The slope b is the predicted change in y for each one-unit increase in x. If hours studied predict test score with b = 4.2, each extra hour is associated with 4.2 more points on average. The intercept a is the predicted y when x = 0, which only means something if x = 0 is realistic.

r² is the fraction of the variation in y explained by the line: r² = 0.81 means 81%.

Cautions

  • Look at the scatter plot: a straight line is only sensible for linear patterns.
  • Don’t extrapolate far beyond the x values in your data.
  • One influential point can swing the line, as the explainer shows.
  • Association is not causation.

Frequently asked questions

What is a residual?

Actual y minus predicted ŷ. Least squares chooses the line that makes the sum of squared residuals as small as possible.

Does it matter which variable is x?

Yes. Regressing y on x gives a different line from regressing x on y. Put the explanatory (predictor) variable on x.