About this calculator
Have pairs of numbers and want to know how they are related? Linear regression finds the straight line that best fits them, written y = mx + b.
Paste your x values in the first box and your y values in the second, in the same order, separated by commas or spaces. Optionally enter an x to predict the matching y.
Worked examples
Real numbers, worked out by the same calculator. Press “Use these numbers” to try one above.
Five points: y = 0.6x + 2.2
- Line of best fit
- y = 0.6x + 2.2
- Slope (m)
- 0.6
- Intercept (b)
- 2.2
- Correlation coefficient (r)
- 0.774597
- R squared
- 0.6
- Number of points
- 5
- Predicted y at x = 6
- 5.8
The best-fit line through 5 points is y = 0.6x + 2.2, with r = 0.774597 (R² = 0.6: 60% of the variation in y is explained by x).
Show the working
- Means: x̄ = 3, ȳ = 4.
- Slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² = 6 ÷ 10 = 0.6.
- Intercept = ȳ − slope × x̄ = 4 − 0.6 × 3 = 2.2.
- Correlation r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² × Σ(y − ȳ)²) = 0.774597.
- Correlation does not prove one thing causes the other, and a line fitted to a small sample can mislead.
A perfect line: y = 2x
- Line of best fit
- y = 2x + 0
- Slope (m)
- 2
- Intercept (b)
- 0
- Correlation coefficient (r)
- 1
- R squared
- 1
- Number of points
- 4
The best-fit line through 4 points is y = 2x + 0, with r = 1 (R² = 1: 100% of the variation in y is explained by x).
Show the working
- Means: x̄ = 2.5, ȳ = 5.
- Slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² = 10 ÷ 5 = 2.
- Intercept = ȳ − slope × x̄ = 5 − 2 × 2.5 = 0.
- Correlation r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² × Σ(y − ȳ)²) = 1.
- Correlation does not prove one thing causes the other, and a line fitted to a small sample can mislead.
Advertising spend (x) against sales (y)
- Line of best fit
- y = 1.39x + 11.7
- Slope (m)
- 1.39
- Intercept (b)
- 11.7
- Correlation coefficient (r)
- 0.998683
- R squared
- 0.997367
- Number of points
- 5
- Predicted y at x = 60
- 95.1
The best-fit line through 5 points is y = 1.39x + 11.7, with r = 0.998683 (R² = 0.997367: 99.736733% of the variation in y is explained by x).
Show the working
- Means: x̄ = 30, ȳ = 53.4.
- Slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² = 1,390 ÷ 1,000 = 1.39.
- Intercept = ȳ − slope × x̄ = 53.4 − 1.39 × 30 = 11.7.
- Correlation r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² × Σ(y − ȳ)²) = 0.998683.
- Correlation does not prove one thing causes the other, and a line fitted to a small sample can mislead.
What you get
- Slope (m): how much y changes for each 1 increase in x
- Intercept (b): the value of y when x is 0
- Correlation coefficient (r): from −1 to 1, how closely the points follow the line
- R squared: the share of the variation in y explained by x
Reading r and R²
An r near 1 means a strong upward line, near −1 a strong downward line, and near 0 no straight-line relationship. An R² of 0.9 means 90% of the variation in y is explained by x. Always look at a scatter plot too: different data sets can share the same line.
Cautions
Correlation is not causation: two things can move together without one causing the other. Predicting far outside the range of your data (extrapolating) is unreliable, and a few points can give a misleading line.
Frequently asked questions
What is linear regression?
Finding the straight line that best fits a set of paired data points, by minimising the squared vertical distances to the line (least squares).
What does R squared tell me?
How much of the spread in y is explained by x, from 0 (none) to 1 (all).
How many points do I need?
At least two, but many more for a reliable line.
Can I predict new values?
Yes: enter an x and the calculator gives the y on the line.
Why did it say the x values are the same?
If every x is identical there is no slope to find: the points form a vertical line.
Formulas tested against hand-worked answers. Last reviewed 29 September 2026. These calculators do arithmetic only; they are not financial, tax or legal advice.