CalculateItNow home

Linear Regression Calculator

Least-squares slope, intercept, equation, r², standard error and a prediction for any x — from up to 10 data pairs, with the residual table shown.

Linear Regression Calculator: with the default inputs, slope (b) is 4.47619.

Try an example
x = 9 is outside the range of your data (1 to 8). Extrapolation assumes the straight line keeps holding, which is exactly the assumption your data cannot check.
Slope (b)
4.47619

How much y changes for a one-unit increase in x.

Intercept (a)
46.857143
Regression equation
y = 4.47619x + 46.857143
r² (variation explained)
0.992363
Correlation r
0.996174
Standard error of the estimate
1.038925
Predicted y
87.142857
Assumptions
  • Ordinary least squares with y regressed on x; all the error is assumed to be in y.
  • The standard error of the estimate uses n − 2 degrees of freedom and needs at least three points.
  • Residuals are assumed independent with constant variance — the usual regression conditions, which the calculator does not test for you.
Data and fitted line
05012345678x
Observed yFitted y
Residuals
xObserved yFitted yResidual
15251.33330.6667
25555.8095-0.8095
36160.28570.7143
46464.7619-0.7619
57069.23810.7619
67273.7143-1.7143
77978.19050.8095
88382.66670.3333

Least squares chooses the line that makes the sum of the squared residuals as small as possible. The residuals themselves always add up to zero.

Math verified by automated testsUpdated 2026-09-092 sources cited

How this is worked out

The formula

Slope:      b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²
Intercept:  a = ȳ − b·x̄
Line:       ŷ = a + b·x

Residual sum of squares:  SSE = Σ(y − ŷ)² = Syy − b·Sxy
Standard error of the estimate:  s = √( SSE ÷ (n − 2) )
r² = 1 − SSE ÷ Syy

Open How it’s calculated above to see this worked through with your own numbers.

What you enter

How many pairs?
Only the first N (x, y) boxes are used. Pairs 6–10 live under More options.from 2 to 10 · whole numbers only · defaults to 8
x1
A number.defaults to 1
y1
A number.defaults to 52
x2
A number.defaults to 2
y2
A number.defaults to 55
x3
A number.defaults to 3
y3
A number.defaults to 61
x4
A number.defaults to 4
y4
A number.defaults to 64
x5
A number.defaults to 5
y5
A number.defaults to 70
x6(under More options)
A number.defaults to 6
y6(under More options)
A number.defaults to 72
x7(under More options)
A number.defaults to 7
y7(under More options)
A number.defaults to 79
x8(under More options)
A number.defaults to 8
y8(under More options)
A number.defaults to 83
x9(under More options)
A number.defaults to 9
y9(under More options)
A number.defaults to 88
x10(under More options)
A number.defaults to 10
y10(under More options)
A number.defaults to 91
Predict y at x =
The line is evaluated here. Staying inside the range of your data is far safer than going outside it.defaults to 9

What you get back

Slope (b)main answer
How much y changes for a one-unit increase in x.
Intercept (a)
The fitted y when x = 0.
Regression equation
r² (variation explained)
Correlation r
Standard error of the estimate
Typical size of a residual, in the units of y. Needs at least 3 points.
Predicted y

What this assumes

  • Ordinary least squares with y regressed on x; all the error is assumed to be in y.
  • The standard error of the estimate uses n − 2 degrees of freedom and needs at least three points.
  • Residuals are assumed independent with constant variance — the usual regression conditions, which the calculator does not test for you.

About this calculator

Simple linear regression finds the one straight line that comes closest to a cloud of points, and then lets you use it. It answers two different questions: how much does y change when x changes (the slope), and what y should I expect at this particular x (the prediction).

What "least squares" means

For any candidate line, each point has a residual — the vertical gap between the observed y and the line. Square those gaps, add them up, and choose the line that makes the total smallest. Squaring is what makes the answer a single tidy formula, and it is also why one far-away point can pull the whole line towards itself.

The residual table below the results shows every gap. Two things are always true and worth checking: the residuals sum to zero, and the line passes exactly through the point (x̄, ȳ).

How to read the results

  • Slope is the headline. Its units are "y-units per x-unit" — dollars per square foot, points per study hour. A slope of 4.48 means each extra hour is associated with about 4.5 more points.
  • Intercept is the fitted value at x = 0. It is often meaningless in itself (nobody has zero square feet), and it is fine for it to be.
  • is the fraction of the variation in y that the line accounts for, from 0 to 1. It is not a verdict on whether the model is right; a curved relationship can have a high r² and still be the wrong shape.
  • Standard error of the estimate is the most under-used number here: it is roughly the typical size of a prediction miss, in the units of y. If it is 1.04 points, your predictions are good to about ±2 points most of the time.

Where it misleads

  • Extrapolation. The line is only evidence about the range of x you actually measured. The calculator warns you when the prediction x falls outside it, because that is where regression goes spectacularly wrong.
  • Regression is directional. Regressing y on x and x on y give different lines (unless r = ±1). Put the thing you want to predict on the y side.
  • Outliers. A single unusual point, especially one with an extreme x, has enormous leverage over the slope. Look at the chart.
  • r² near 1 with two or three points is meaningless — two points always fit a line perfectly.
  • Finally, the slope is an association, not a causal effect, unless the x values were assigned by an experiment.

Frequently asked questions

How do I find the line of best fit by hand?

Compute the two means, then the slope as Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)². The intercept is ȳ − slope × x̄. The steps above show each of those sums for your data.

What does r² of 0.99 mean?

That the straight line accounts for 99% of the variation in y. It does not mean the relationship is causal, nor that a straight line is the right shape — only that the line fits these points closely.

What is the standard error of the estimate?

The typical vertical distance between the data points and the line, in the units of y. About two-thirds of points fall within one standard error of the line, and it is the right number for quoting prediction accuracy.

Can I predict y for an x outside my data?

You can, and the calculator will do it, but the line is only supported by the range you measured. Extrapolation assumes the relationship continues unchanged, and that assumption breaks more often than not.

Why do I get a different line if I swap x and y?

Least squares minimises vertical distances, so it treats y as the thing being predicted. Swapping the roles minimises horizontal distances instead and gives a different slope — the two agree only when the fit is perfect.

Put this calculator on your own site

A working linear regression, free for any site, with no ads and no sign-up. It resizes to fit wherever you paste it and updates itself as this page improves.

Paste this anywhere. It works on any site, carries no ads, never expires, and always shows the current version.

Linear Regression Calculator by CalculateItNow

The page's own title. The clearest description of what the link leads to.

The credit line sits outside the widget on purpose, so it is a real link on your page rather than one buried in a frame. Please keep it — it is what pays for CalculateItNow staying free and ad-free. The script only resizes the widget to fit its contents; drop it and the widget still works.

Browse every calculator widget·How to add it to WordPress, Squarespace or Wix

The questions people ask next to a linear regression.

All math calculators·Browse everything