What the line of best fit is
Linear regression finds the straight line ŷ = a + bx that keeps the squared vertical distances between the points and the line as small as possible (least squares). The slope b tells you how much y changes, on average, for each one unit increase in x.
a = ȳ − b·x̄
r = Σ(x − x̄)(y − ȳ) ÷ √[Σ(x − x̄)² · Σ(y − ȳ)²]
Worked example
For hours studied 1 to 8 and scores 52, 55, 61, 64, 68, 70, 77, 79, the line is ŷ = 48.071 + 3.929x. Each extra hour is linked with about 3.93 more points. The correlation is r = 0.994 and R² = 0.989, so about 99% of the variation in scores is explained by hours studied.
Reading r and R²
| |r| | Usual description |
|---|---|
| 0.7 to 1 | Strong |
| 0.4 to 0.7 | Moderate |
| 0.2 to 0.4 | Weak |
| below 0.2 | Very weak or none |
The sign of r matches the direction of the line. R² is r squared and reads as the share of variation explained. These labels are rules of thumb; what counts as strong differs between fields.
Cautions
- Correlation is not causation. A strong r shows the variables move together, not that one causes the other.
- Do not extrapolate far. Predictions well outside the range of your X values can be badly wrong.
- Look at the plot. A curved pattern or one extreme point can produce a misleading r. The scatter plot above is there for that reason.
Formulas follow the NIST/SEMATECH e-Handbook of Statistical Methods: least squares.
Frequently asked questions
What is the difference between r and R²?
r is the correlation coefficient, from −1 to 1, and shows strength and direction. R² is r squared, from 0 to 1, and shows the share of the variation in y explained by the line.
How many points do I need?
At least three for the calculator, but a meaningful regression needs many more. With very few points, a high r can happen by chance.
Does it matter which variable is X?
Yes for the line: X should be the variable you use to predict, Y the one you predict. The correlation r is the same either way.