This linear regression calculator fits the least-squares line to your paired data and reports the full regression story: slope, intercept, correlation r, R², the standard error of the estimate — and predictions for any x you supply.


Equation–
Correlation r–
R²–
Std. Error of Estimate–
Prediction–

Least squares minimizes the sum of squared vertical residuals. Extrapolating far beyond your x-range is speculation with good posture — the Prediction card is most trustworthy inside (or just past) the data’s span.

Least Squares, Honestly Explained

The line ŷ = a + bx minimizes the sum of squared gaps between points and line — Gauss's criterion, chosen because squares penalize big misses and make the math land on closed forms: b = Σ(x−x̄)(y−ȳ) / Σ(x−x̄)² and a = ȳ − b·x̄ (the line always passes through the data's center of mass (x̄, ȳ)). The companion r measures pure linear association (see our Correlation Calculator); R², its square, states the share of y's variance the line accounts for. Part of our Statistics Calculators collection.

Worked Example (Verified)

Data: (1,2), (2,3), (3,5), (4,4), (5,6) — the widget's defaults:

  • x̄ = 3, ȳ = 4 · slope b = 9 ÷ 10 = 0.900 · intercept a = 4 − 0.9 × 3 = 1.300 → ŷ = 1.3 + 0.9x
  • r = 0.900, R² = 0.810 — the line explains 81% of y's variation; standard error of the estimate ≈ 0.80
  • Prediction at x = 6: ŷ = 1.3 + 5.4 = 6.7 (one step beyond the data — mild extrapolation, flagged as such)

Warnings the Equation Won't Give You

  • Anscombe's quartet: four wildly different datasets share this example's near statistics — always plot. Curved truth + straight model = confident nonsense.
  • Outliers drag least-squares lines disproportionately (the square again); check influential points before quoting slope to three figures.
  • Correlation from aggregated or range-restricted data misleads in both directions; and regression toward the mean is a property of imperfect correlation, not a force.
  • Swap x and y and you get a different line (the regression of x on y) unless |r| = 1 — regression is directional by design.

Related Tools

Frequently Asked Questions

How do you calculate linear regression?

Slope b = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)²; intercept a = ȳ − b·x̄. For the example data: b = 0.9, a = 1.3, giving ŷ = 1.3 + 0.9x with r = 0.90.

What does R² mean?

The proportion of variance in y that the fitted line accounts for: R² = 0.81 means 81% explained, 19% left in the residuals. It's the right "how good is the fit" headline — though high R² never proves causation and low R² doesn't disprove a real relationship.

What is the standard error of the estimate?

The typical size of a residual: √(SSE ÷ (n−2)) — roughly the average miss distance of points from the line, in y's units. Prediction intervals are built from it (plus leverage), wider than confidence intervals for the line itself.

Can I predict outside my data range?

You can compute it — the calculator happily will — but extrapolation assumes the linear pattern persists where you have no evidence. Inside the range, trust it with the standard error in mind; a step or two past, tentatively; far past, not at all.

Why did my slope change when I swapped the columns?

Regression of y-on-x minimizes vertical errors; x-on-y minimizes horizontal ones. They give different lines meeting at (x̄, ȳ), identical only when |r| = 1. Choose the direction matching what you want to predict.

Is this linear regression calculator free?

Yes — free, instant, and your data never leaves the browser.