Linear Regression Calculator
Test cases replayed : 2 of 2 match · Methodology · No outside source listed
Paste two lists of paired values, x and y, in the same order to fit the least-squares line and predict y for a new x.
Result
Regression line
Slope (b)
- Intercept (a)
- Predicted y at that x
- Correlation coefficient (r)
- Coefficient of determination (r²)
- Number of pairs
- Note
Estimate for planning only, not tax, legal, financial or medical advice. This calculator uses the method explained on this page.
This browser did not allow copying. The sentence is in the box below, already selected: copy it with your keyboard or the menu.
How to use this calculator
Fill in the fields in this order; each step takes you to its field.
- x values (separated by commas, spaces or new lines): type or paste your values.
- y values, same order and count: type or paste your values.
- x value to predict y for: enter a number.
- Read the result: Regression line; the panel also shows Slope (b), Intercept (a), Predicted y at that x, Correlation coefficient (r), Coefficient of determination (r²), Number of pairs and Note.
Data plot
Table of values
| x | y |
|---|
How this calculator works
Ordinary least squares fits the line y = a + bx that makes the sum of squared vertical distances from the points smallest: slope b = Σ(xᵢ − x̄)(yᵢ − ȳ) ÷ Σ(xᵢ − x̄)², intercept a = ȳ − b x̄.
r is Pearson's correlation coefficient and r² the share of the variance of y explained by the line. A prediction far outside the range of the x values is an extrapolation and may not hold.
Worked example
| x values (separated by commas, spaces or new lines) | 1, 2, 3, 4, 5 |
|---|---|
| y values, same order and count | 2, 4, 5, 4, 5 |
| x value to predict y for | 6 |
| Regression line | y = 2.2 + 0.6x |
|---|---|
| Slope (b) | 0.6 |
| Intercept (a) | 2.2 |
| Predicted y at that x | 5.8 |
| Correlation coefficient (r) | 0.7746 |
| Coefficient of determination (r²) | 0.6 |
| Number of pairs | 5 |
Frequently asked questions
What is the regression line for x = 1 to 5 and y = 2, 4, 5, 4, 5?
y = 2.2 + 0.6x, with r² = 0.6; at x = 6 the line predicts y = 5.8.
Is least-squares regression the same as linear regression?
Yes for a straight line: simple linear regression is usually fitted by ordinary least squares, the method used here.