Skip to content
Math & Statisticsstatistics

Linear Regression Calculator

Least-squares line of best fit, with R squared and a prediction. The line always passes through the mean of both variables, which is a useful check on any regression.

Also called: least squares calculator, line of best fit.

Separate values with commas or spaces.

Separate values with commas or spaces.

Line of best fit
y = 0.7714x + 1.8

y = 0.7714x + 1.8. It explains 77.14% of the variation. At x = 7 the line predicts y = 7.2, though that is outside the data you fitted.

Slope
0.77
Intercept
1.8
R squared
0.77
Variation explained
77.14%
Prediction
7.2
Standard error of the estimate
0.88
Method and background

How this is calculated

Least squares finds the line minimising the sum of squared vertical distances to the points. The slope is the covariance over the variance of x, and the intercept follows from the line passing through the point of both means, which is worth remembering as a sanity check. R squared says how much of the variation the line accounts for, and the standard error says how far a typical point sits from it.

least squares: the slope is covariance over the variance of x, and the line passes through both means
b
Slope
a
Intercept

Worked examples

Each of these is asserted on every build. If a change to the engine ever moved one of these answers, the build would fail before the page could print it.

a modest upward fit

X values
1, 2, 3, 4, 5, 6
Y values
2, 4, 5, 4, 5, 7
Predict y at x =
7

Line of best fity = 0.7714x + 1.8

Least squares computed independently

Open this example

a perfect line fits exactly

X values
1, 2, 3, 4
Y values
2, 4, 6, 8
Predict y at x =
5

Line of best fity = 2x + 0

boundary

Open this example

Method and limits

What it assumes

  • A linear relationship, with errors of roughly constant spread.

What it deliberately does not model

  • Predicting outside the range of the data is extrapolation and the model has no evidence there.
  • A high R squared does not mean the model is correct, only that it fits these points.

Formula version 1.0.0 · definition 1.0.0 · India · Report a problem with this calculator

Frequently asked questions

Can I trust a prediction beyond my data?
No. The line was fitted where the data is and says nothing about behaviour outside it. Extrapolation is where regressions embarrass people.
Why squared distances?
Squaring makes the problem have a unique closed-form solution and penalises large misses more. Minimising absolute distances is also valid and much harder to compute.