Linear Regression
Best-fit line y = mx + b with R²

🔒 Locally run · Method · · Disclaimer · Linear Regression
Linear Regression turns the numbers behind best-fit line y = mx + b with R² into a result, step by step. You supply X values (comma separated) and Y values (comma separated) to Linear Regression; the answer follows at once. Linear Regression ties each output to its formula. Students and professionals reach for Linear Regression when speed matters. Linear Regression runs in your browser. Math data stays in the tab. Linear Regression sits in the Math section next to related tools and linear regression calculator least squares slope intercept r squared. Linear Regression is great for comparing scenarios. Change one value and watch. Linear Regression is free, instant and local.
What the defaults give
x = 1, 2, 3, 4 against y = 2, 4, 6, 8 fits y = 2.0000x + 0.0000.
R² is 1.0000, a perfect fit, because every y value is exactly twice its x value.
The least-squares formulas
slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
intercept = ȳ − slope × x̄
R² = (Σ(x − x̄)(y − ȳ))² ÷ (Σ(x − x̄)² × Σ(y − ȳ)²)
With x̄ = 2.5 and ȳ = 5, the slope comes out at 2 and the intercept at 0, so the line passes through the origin.
Worked examples
(1,2) (2,4) (3,6) (4,8) → y = 2x + 0, R² = 1
(1,2) (2,3) (3,5) (4,6) → positive slope below 2, R² near 0.96
(1,10) (2,8) (3,6) (4,4) → y = −2x + 12, R² = 1
(1,5) (2,5) (3,5) (4,5) → slope 0, intercept 5
What R² does and does not say
R² is the share of the variation in y explained by the line. A value near 1 means the points sit close to it; near 0 means the line explains almost nothing. It says nothing about whether the relationship is causal, whether the slope is meaningful, or whether a straight line was the right shape to begin with. A strong R² on a curved relationship is still the wrong model.
When a straight line misleads
- Outliers. A single distant point can swing both the slope and R² dramatically.
- Curvature. Growth and decay are rarely linear; a log or quadratic fit may be the honest one.
- Extrapolation. A line fitted over 1–4 says little about x = 40.
- Correlation versus cause. Two variables moving together may share a third driver entirely.
A perfect fit, with R² of 1.0, is a warning as much as a result: real measurements almost never fall exactly on a line, so an exact fit usually means the data were constructed or too few points were used. The slope is the quantity to interpret — 2.0 means y rises two units for every unit of x — while the intercept is where the line crosses zero, which can sit outside the data range and be meaningless in context.
Frequently Asked Questions
Why is the slope 2 for these points?
Because each y value is exactly twice its x value, so the best-fit line is y = 2x with no intercept and R² of 1.
What does R² = 1 mean?
That every point lies exactly on the fitted line — all the variation in y is explained by x, which is unusual in real data.
How many points do I need?
At least two for a line, but three or more before R² tells you anything useful about the fit.
Does a high R² prove causation?
No. It only measures how closely the points follow the line, not why they do.
What happens with an outlier?
Least squares weights distant points heavily, so one outlier can rotate the line and pull R² down sharply.
Can I fit a curve instead?
Not with this tool. Transform the data — for example take logs of y — and fit a line to the transformed values.
Octahedron Volume and other Math tools
Octahedron Volume · Digital Root Calculator · Fraction Calculator · Matrix Determinant · Trigonometry Calculator · Random Number Generator · Math Guides