Regression Calculator

Simple linear regression (least squares).

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Enter one x,y pair per line to get the best-fit straight line. The points (1,2), (2,3), (3,5), (4,7) give y = 1.7x + 0.

How to use

1
Step 1
Type one x,y pair per line, like 1,2.
2
Step 2
Add at least two pairs.
3
Step 3
Press Calculate to see the slope, intercept and line.

How it works

The least-squares line minimises the sum of squared vertical distances to the points. Slope m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and intercept b = ȳ − m x̄. For the first example x̄ = 2.5 and ȳ = 4.25, so m = 8.5 ÷ 5 = 1.7 and b = 4.25 − 1.7 × 2.5 = 0.

m = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²      b = ȳ − m·x̄

Worked example

Three points on a curve

Input
(1,1), (2,4), (3,9)
Output
y = 4x − 3.333333
Walkthrough
x̄ = 2, ȳ = 4.6667. Σ(x − x̄)(y − ȳ) = 8 and Σ(x − x̄)² = 2, so m = 4 and b = 4.6667 − 8 = −3.3333.

Limitations

  • Needs at least two pairs.
  • Gives the slope and intercept only; use the correlation calculator for r.
  • Fitting a line to curved data, as in the x² example, gives a poor fit.

Questions

What is the best-fit line for (1,2), (2,3), (3,5), (4,7)?
y = 1.7x + 0.
What is the line through (1,3), (2,5), (3,7), (4,9), (5,11)?
y = 2x + 1, since the points are exactly linear.
Does it give R²?
No. Square the output of the correlation calculator to get R².

Features

  • Slope and intercept
  • Any number of points
  • Runs in your browser

Guides

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Statistics intro: Mean, median, and mode

    Khan Academy

    Intro framing before pasting datasets into stats calculators.

    Watch on YouTube
  • The essence of calculus

    3Blue1Brown

    Visual calculus story that complements symbolic solvers.

    Watch on YouTube
  • Probability

    Math is Fun

    Probability basics for combo and chance calculators.

  • OpenStax Math

    OpenStax

    Free textbooks for algebra through calculus.