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
Your results
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
Worked example
Using the default values shown in the calculator:
| X values | 1, 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 |
- Slope b = 2.0200 and intercept a = -0.0200.
- So y = -0.0200 + 2.0200 x; at x = 8 the prediction is 16.14.
Result:
| Line of best fit | y = -0.0200 + 2.0200 x |
|---|---|
| Slope b | 2.0200 |
| Intercept a | -0.0200 |
| Predicted Y at your X | 16.1400 |
| r² | 0.9982 |
| Pairs | 6 |
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
Related calculators
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.
