Line of Best Fit: Linear Regression and Correlation Explained
On this page
A line of best fit is the straight line that follows a scatter of points as closely as possible. The least-squares line makes the total of the squared vertical gaps (residuals) as small as it can be. The correlation coefficient , between and , says how tightly the points hug a straight line.
The formulas
The line always passes through the mean point .
Worked example 1
| 1 | 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|
| 2.1 | 3.9 | 6.2 | 7.8 | 10.1 | 12.2 |
Working through the sums gives and :
Each step of 1 in adds about 2 to , and is very close to 1.
Worked example 2: a negative trend
For and , the line is . The negative slope means falls as rises.
Reading r and r²
| Relationship | |
|---|---|
| close to | strong positive |
| close to | little or no linear relationship |
| close to | strong negative |
is the fraction of the variation in that the line explains: means 95%.
Predicting with the line
Substitute an -value: with , at we predict . Predicting far outside your data range (extrapolation) is risky.
Common mistakes
- Swapping and : the line for predicting from is different.
- Trusting a line when is near 0.
- Extrapolating far beyond the data.
Practice questions
- If , what kind of relationship is it?
- If , what is ?
- Using , predict at .
Answers: 1) strong negative 2) 0.36 3) 20.18
Paste your own data into the linear regression calculator to get the line, , and a scatter plot with residuals. For single-variable summaries, see mean, median and mode.
Frequently asked questions
Why square the residuals?
Squaring makes all gaps positive and penalises big misses more, and it gives a neat formula for the best line.
What is a residual?
The vertical distance between a data point and the line: actual y minus predicted y.
Can a curve fit better than a line?
Yes. If the scatter bends, a curved model may fit better than a straight line.
#statistics#regression#data
