standarddeviationcalculator.net

Linear regression calculator

Enter your paired data to get the least-squares line, how much of the variation it explains, and whether the slope is distinguishable from zero. The working shows every quantity the fit is built from, so you can check it by hand.

x (predictor)y (outcome)Remove

One row per observation. x is the variable you know; y is the one you want to predict from it. Swapping the columns gives a different line.

The formulas

The slope and intercept of the least-squares line are:

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

The numerator of the slope is the same quantity that drives the correlation coefficient. The difference is the denominator: correlation divides by the spread of both variables and comes out unitless, while regression divides by the spread of x alone and comes out in units of y per unit of x. That is what makes the slope interpretable and r comparable.

What "least squares" actually minimises

For any candidate line, each point has a residual — the vertical gap between the observed y and the y the line predicts. Least squares picks the line that makes the sum of those residuals squared as small as possible.

Squaring does two things. It stops positive and negative residuals cancelling, and it penalises large misses disproportionately: a residual of 4 counts sixteen times as much as one of 1. That second property is why a single outlier can visibly tilt a regression line, and why it is worth plotting the data before trusting the fit.

Reading the output

QuantityWhat it tells you
Slope (b)Change in y per one-unit increase in x
Intercept (a)Predicted y at x = 0; often not meaningful on its own
Share of the variation in y explained by x
Standard error of estimateTypical prediction error, in units of y
Standard error of slopeHow precisely the slope itself is pinned down
t and pWhether the slope is distinguishable from zero

Testing the slope

A fitted line always has some slope, even on random data. The question is whether it is further from zero than sampling noise would produce:

t = b ÷ SE(b), with df = n − 2

Two degrees of freedom are spent estimating the slope and the intercept, which is why the test needs at least three points — with two points the line fits perfectly and there is nothing left over to measure error with. The p value from this test is identical to the one testing whether r differs from zero; they are the same hypothesis stated two ways.

What the model assumes

Least squares is easy to compute on any data at all, which makes it easy to apply where it does not belong. The fit is only trustworthy if:

The famous warning

Anscombe's quartet is four datasets that share the same slope, intercept, r² and standard errors to two decimal places — and look nothing alike. One is a clean linear relationship, one is a perfect parabola, one is a straight line with a single outlier, and one is a vertical stack with one distant point that manufactures the entire fit.

Any regression summary that has not been checked against a scatter plot could be describing any of them. That is why the plot above is not decoration.

Common questions

What is linear regression?

It fits the straight line y = a + bx that comes closest to a set of paired points, so you can describe how y changes with x and predict y at an x you have not measured.

"Closest" has a precise meaning: the line that minimises the sum of the squared vertical distances from the points to the line. That is why it is called least squares.

What do the slope and intercept mean?

The slope (b) is the change in y for a one-unit increase in x. If the slope is 2.5, then every extra unit of x is associated with 2.5 more units of y.

The intercept (a) is the predicted y when x is zero. It is often meaningless in itself — predicted weight at height zero, say — and exists mainly to position the line at the right height.

Why does the line have to pass through the mean point?

Because of how least squares works: the intercept is defined as a = ȳ − b·x̄, which forces the line through (x̄, ȳ) exactly. Every least-squares line passes through the centre of gravity of the data. It is a useful check — if your fitted line misses that point, the arithmetic went wrong.

What is the standard error of the estimate?

The typical size of a residual — how far the actual points sit from the line, in the units of y. It is the standard deviation of the prediction errors, and it is the number that tells you how much to trust a prediction.

An r² of 0.9 sounds excellent, but if the standard error of the estimate is 40 units and you need predictions accurate to 5, the model is no use to you. r² measures relative fit; the standard error measures absolute accuracy.

Does swapping x and y give the same line?

No. Regressing y on x minimises vertical distances; regressing x on y minimises horizontal ones. The two lines differ unless the correlation is perfect, and they cross at the mean point.

So the choice of which variable is the predictor matters. Put the variable you will know in advance in the x column, and the one you want to predict in y.

Can I predict beyond the range of my data?

You can compute it, but you should not trust it. Extrapolation assumes the straight-line relationship continues past where you measured, and there is nothing in the data to support that. Relationships that are near-linear over a narrow range routinely bend outside it. The chart on this page deliberately draws the line only across the x values actually observed.

Related calculators

Written and reviewed by our editorial team. Last updated . Method and sources: how these numbers are computed.