Statistics & Probability

Linear Regression Calculator (Line of Best Fit)

Enter X and Y values to get the line of best fit and predict Y for a new X.

Your numbers

Separate numbers with commas, spaces or new lines. You can paste a column from a spreadsheet.
Separate numbers with commas, spaces or new lines. You can paste a column from a spreadsheet.

Your results

Line of best fit
Line of best fit
—
Slope b
—
Intercept a
—
Predicted Y at your X
—
r²
—
Pairs
—

Linear Regression Calculator (Line of Best Fit) by TheCalcTools

How the Linear Regression Calculator (Line of Best Fit) works

Least-squares regression finds the straight line that makes the sum of squared vertical distances from the points to the line as small as possible.

The slope is the covariance of X and Y divided by the variance of X. The line always passes through the point (mean of X, mean of Y), which gives the intercept.

Predictions far outside the range of your X values (extrapolation) are much less reliable than predictions inside it.

The formula

b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², a = ȳ − b × x̄Prediction: ŷ = a + b × x

Worked example

Using the default values shown in the calculator:

X values1, 2, 3, 4, 5, 6
Y values (same order)2.1, 3.9, 6.2, 7.8, 10.1, 12.2
Predict Y at X =8
  1. Slope b = 2.0200 and intercept a = -0.0200.
  2. So y = -0.0200 + 2.0200 x; at x = 8 the prediction is 16.14.

Result:

Line of best fity = -0.0200 + 2.0200 x
Slope b2.0200
Intercept a-0.0200
Predicted Y at your X16.1400
r²0.9982
Pairs6

Frequently asked questions

What does the slope mean?

It is the average change in Y for each one-unit increase in X. A slope of 2 means Y rises by about 2 for every extra unit of X.

How good is the fit?

Look at r². Close to 1 means the points lie close to the line. Also plot the residuals: a pattern means a straight line is the wrong model.

Sources and further reading

More in Statistics & Probability · All calculators

This calculator gives estimates for information only. Check important results independently before you rely on them. See our disclaimer.