Linear Regression Calculator
Enter paired x and y values to find the least squares regression line y = a + bx, the correlation coefficient r, R² and a predicted y for any x.
Least squares regression formulas
b = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² a = ȳ − b × x̄ y = a + bx
The least squares line is the straight line that makes the sum of squared vertical distances from the points as small as possible.
Worked example
For x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5: x̄ = 3, ȳ = 4, Σ(x − x̄)(y − ȳ) = 6 and Σ(x − x̄)² = 10. So b = 0.6, a = 4 − 0.6 × 3 = 2.2, giving y = 2.2 + 0.6x. r ≈ 0.775 and R² = 0.6.
Interpreting r and R²
| |r| | Strength |
|---|---|
| 0.0–0.3 | Weak |
| 0.3–0.7 | Moderate |
| 0.7–1.0 | Strong |
R² is the share of the variation in y explained by the line. Correlation does not prove that x causes y.
Frequently asked questions
What is a line of best fit?
The straight line that best represents the trend in scattered data, usually found by least squares.
What does the slope mean?
How much y changes, on average, for each one-unit increase in x.
What is the difference between r and R²?
r gives the direction and strength of the linear relationship; R² is r squared and gives the share of variation explained.
Should I predict outside my data range?
Be careful. Extrapolating beyond the observed x values can be unreliable.
Related calculators
- Average CalculatorMean, median, mode and range of any list of numbers.
- Z-Score CalculatorZ-score, percentile and normal probabilities.
- Mean Absolute Deviation CalculatorMean absolute deviation of a data set, with steps.
- Coefficient of Variation CalculatorCoefficient of variation from data or mean and SD.
- Factor CalculatorList all factors, factor pairs and the prime factorization.
- Area CalculatorArea of rectangles, circles, triangles and 5 more shapes.