Linear Regression
Fit the least-squares line and get the slope, intercept, equation, r, and r².
slope b₁ = 0.8 · intercept b₀ = 1.8 · r = 0.8528 · r² = 0.7273
This tool fits the least-squares regression line ŷ = b₀ + b₁x to your paired data, returning the slope, intercept, correlation r, and r². For x = 1–5 and y = 2, 4, 5, 4, 6, it gives ŷ = 1.8 + 0.8x with r² = 0.7273 — meaning about 73% of the variation in y is explained by x.
What the least-squares line is
Linear regression draws the single straight line that best summarises how y changes with x. “Best” means least squares: the line that makes the sum of the squared vertical distances between each point and the line as small as possible. The slope b₁ is how much ŷ moves per one-unit rise in x; the intercept b₀ is the predicted y when x = 0.
The coefficient of determination, r², is the share of the variance in y that the line explains — from 0 (the line is no better than the mean of y) to 1 (every point lies exactly on the line). It is simply the square of Pearson’s correlation r.
slope is covariation over the spread of x; the intercept anchors the line through (x̄, ȳ)
Worked example
Five pairs — x: 1, 2, 3, 4, 5 and y: 2, 4, 5, 4, 6. Here x̄ = 3 and ȳ = 4.2.
- 1 Find the means. x̄ = (1+2+3+4+5) ÷ 5 = 3 and ȳ = (2+4+5+4+6) ÷ 5 = 4.2.
- 2 Build the sums of squares. Σ(x−x̄)(y−ȳ) = 4.4 + 0.2 + 0 − 0.2 + 3.6 = 8 and Σ(x−x̄)² = 4 + 1 + 0 + 1 + 4 = 10.
- 3 Compute the slope. b₁ = 8 ÷ 10 = 0.8.
- 4 Compute the intercept. b₀ = ȳ − b₁·x̄ = 4.2 − 0.8 × 3 = 1.8, so ŷ = 1.8 + 0.8x.
- 5 Assess the fit. r = 8 ÷ √(10 × 8.8) ≈ 0.8528, so r² ≈ 0.7273 — about 73% of the variance in y is explained.
Interpreting r² (goodness of fit)
Rough bands for the share of variance explained; the right cutoffs depend on your field.
| r² | Variance explained | Fit |
|---|---|---|
| 0.00–0.25 | 0–25% | weak / little linear fit |
| 0.25–0.50 | 25–50% | modest |
| 0.50–0.75 | 50–75% | moderate |
| 0.75–0.90 | 75–90% | strong |
| 0.90–1.00 | 90–100% | very strong |
Reading the result responsibly
Correlation is not causation. A good fit means x predicts y in this sample — not that changing x causes y to change. A lurking third variable can drive both.
Don’t extrapolate beyond the data. The line is only supported over the range of x you measured. Predictions far outside that range assume the linear pattern continues, which it often does not.
r versus r². r (−1 to +1) carries the direction of the relationship; r² (0 to 1) is the share of variance explained and is always positive. An r of −0.85 and +0.85 give the same r² of about 0.72.