Linear Regression Calculator
Fit a straight line to your data by least squares, and find the correlation coefficient r, R² and predictions.
Line of best fit
y = 1.99x + 0.05
- Correlation (r)
- 0.9987 positive, very strong
- R²
- 0.9973
- Predicted y at x = 6
- 11.99
The best-fit line is y = 1.99x + 0.05, with a very strong positive correlation (r = 0.999). At x = 6, it predicts y ≈ 11.99.
How it's worked out
- Meansx̄ = 3, ȳ = 6.02
- Slope
Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)²1.99 - Intercept
ȳ − slope × x̄0.05 - Correlation
Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² Σ(y − ȳ)²)0.998652
- Correlation shows that two things move together, not that one causes the other. Predictions far outside your data are unreliable.
The formulas
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² · a = ȳ − b x̄ · r = Σ(x − x̄)(y − ȳ) ÷ √(Σ(x − x̄)² Σ(y − ȳ)²)
Worked example
For (1, 2.1), (2, 3.9), (3, 6.2), (4, 7.8), (5, 10.1), the line is y = 1.99x + 0.05 with r above 0.99, and it predicts y ≈ 11.99 at x = 6.
Questions people ask
How is the line of best fit calculated?
By least squares: slope = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)², and intercept = ȳ − slope × x̄.
What does r mean?
The correlation coefficient, from −1 to 1. Near 1 is a strong positive relationship, near −1 a strong negative one, near 0 little or none.
What is R²?
The share of the variation in y that the line explains.
About this calculator
Formula and rules last checked 25 October 2026Written and tested by the CalculatorDex teamReport a problem
