Regression Calculator
Simple linear regression (least squares).
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
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)?
What is the line through (1,3), (2,5), (3,7), (4,9), (5,11)?
Does it give 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 YouTubeThe 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.