Linear Regression Calculator
The line of best fit through paired data — slope, intercept, r², and a prediction for any value of x.
Least-squares regression finds the straight line that minimises the total squared vertical distance from the points.
How the linear regression calculator works
Least-squares regression finds the straight line that minimises the total squared vertical distance from the points. The slope is the covariance divided by the variance of x, and the line always passes through the mean of both variables, which is a useful check.
The slope is the interpretable number: it says how much y changes for a one-unit rize in x. r² says how much of the variation the line accounts for. Predicting outside the range of your data is extrapolation, and the line has no evidence for it whatever the arithmetic returns.
Formula: slope = Σ(x−x̄)(y−ȳ) ÷ Σ(x−x̄)²; intercept = ȳ − slope × x̄
Worked examples
| Inputs | Slope | Note |
|---|---|---|
| A rizing trend | 0.904762 | slope ≈ 0.86 |
| A perfect line y = 2x + 1 | 2 | slope exactly 2 |
| A falling trend | -2 | slope −2 |
FAQFrequently asked questions
What does the slope mean?
How much y changes for a one-unit increase in x. It is the number worth interpreting.
What is least squares?
The line that minimises the total squared vertical distance from the points to the line.
What is a good r²?
It depends entirely on the field. In physics 0.99 may be poor; in social science 0.3 can be a real finding.
Can I predict beyond my data?
The arithmetic will, but the evidence does not. The calculator flags it when your prediction falls outside the range of your x values.
Does a good fit prove causation?
No. A line through correlated data says nothing about which variable drives which, or whether a third does.
Where these figures come from
- NIST Digital Library of Mathematical Functions — reference definitions for elementary and special functions
- Wolfram MathWorld — definitions and formulas for every topic on this page
- NIST/SEMATECH e-Handbook of Statistical Methods — the statistical formulas (mean, variance, z, confidence intervals, sample size)
- Common Core State Standards — Mathematics — the terms and methods taught in US schools
Last checked: September 2026. Formulas are fixed by mathematics and do not change with tax years or regulations.