Linear Regression Calculator
Find the best-fit line (ŷ = a + bx), correlation (r), and R² from your data — plus a clean scatter plot, optional residuals, and step-by-step.
Background
Linear regression models how y changes with x. The slope b tells you “per +1 in x, y changes by b”. R² tells you how much of the variation in y is explained by x.
How to use this calculator
- Choose Pairs, Lists, or Summary stats.
- Click Calculate to get ŷ = a + bx, r, and R².
- Use Predict to compute ŷ for a chosen x.
- Turn on Residuals if you want error-by-point.
How this calculator works
- Compute means x̄, ȳ.
- Compute sums Sxx, Sxy, Syy.
- Slope: b = Sxy/Sxx.
- Intercept: a = ȳ − b·x̄.
- Correlation: r = Sxy/√(Sxx·Syy), and R² = r².
Formula & Equation Used
Regression line: ŷ = a + bx
Slope: b = Sxy/Sxx
Intercept: a = ȳ − b·x̄
Correlation: r = Sxy / √(Sxx·Syy)
Residual: e = y − ŷ
Example Problem & Step-by-Step Solution
Example 1 — Study hours vs exam score
- Data points: (1, 55), (2, 58), (3, 65), (4, 70), (5, 74)
- Compute x̄ and ȳ, then Sxx and Sxy.
- Slope: b = Sxy/Sxx, Intercept: a = ȳ − b·x̄.
- Final line: ŷ = a + bx lets you predict scores from hours.
Example 2 — Negative correlation (more gaming, lower grade)
- Data points: (1, 92), (2, 88), (3, 83), (4, 79), (5, 73)
- The slope b comes out negative → y tends to decrease as x increases.
- r will be negative; R² tells how tight the trend is.
Example 3 — Summary stats (exam-style)
- Given: n = 10, x̄ = 5, ȳ = 70, Sxx = 40, Sxy = 60, Syy = 120
- Slope: b = 60/40 = 1.5
- Intercept: a = 70 − 1.5·5 = 62.5
- So the line is ŷ = 62.5 + 1.5x
Frequently Asked Questions
Q: What does a negative slope mean?
It means that as x increases, y tends to decrease.
Q: What does R² mean?
It’s the fraction of variability in y explained by x (for a linear model).
Q: Why do I see an “extrapolation” warning?
Because your x is outside the data range—predictions can be unreliable there.