Correlation coefficient and residuals: Formulas and a worked example
Correlation summarizes the direction and strength of a linear relationship, while a residual describes one point’s vertical gap from the fitted line. We’ll calculate both from the same seven points and use the fitted equation to see how the residuals balance.
Read the correlation coefficient
Pearson’s correlation coefficient measures linear association and lies between and . Values close to indicate strong positive linear association, and values close to indicate strong negative linear association. A value near indicates weak linear association; a curved relationship can still be present.
The sign gives the direction, and gives the strength of the linear association. A correlation of means the points lie on a line with negative slope; it does not specify a slope of . Values such as and are sometimes used as rough descriptive cutoffs, with interpretation depending on the context.
Use consistent sample standard deviations
For paired observations, with positive sample standard deviations and , use
Each parenthesized quantity is a standardized deviation, or z-score. The sample standard deviations use in their variance denominators. Correlation is undefined if either variable has zero standard deviation.
Example: Calculate correlation for seven points
| x | y |
|---|---|
| 0 | 0.8 |
| 2 | 1.0 |
| 4 | 0.2 |
| 6 | 0.2 |
| 8 | 2.0 |
| 10 | 0.8 |
| 12 | 0.6 |
The means are and . Add squared deviations and products of matching deviations to get the three sums below.
The two sample standard deviations and the equivalent centered-sums formula give
This is a weak positive linear relationship. The centered-sums formula gives the same correlation as the standardized-deviation formula when the standard deviations are used consistently.
Find the fitted line without rounding its coefficients
The ordinary least-squares slope is . The intercept is .
The approximate line is . We’ll use the exact fractions for the remaining calculations.
A residual is actual minus predicted
A point above the fitted line has a positive residual. A point below it has a negative residual. The residual is a signed vertical difference; its absolute value is the vertical distance.
At , the predicted value is . Subtracting gives a relatively large positive residual.
At , the residual is , so that point lies just below the fitted line.
| x | Actual y | Predicted ŷ | Residual e |
|---|---|---|---|
| 0 | 0.8000 | 0.7143 | 0.0857 |
| 2 | 1.0000 | 0.7429 | 0.2571 |
| 4 | 0.2000 | 0.7714 | -0.5714 |
| 6 | 0.2000 | 0.8000 | -0.6000 |
| 8 | 2.0000 | 0.8286 | 1.1714 |
| 10 | 0.8000 | 0.8571 | -0.0571 |
| 12 | 0.6000 | 0.8857 | -0.2857 |
Inspect the residual plot
Plotting residuals against x helps us look for systematic curvature or changing spread. A curved pattern suggests that a linear equation is missing part of the relationship. In this example, the residuals balance around zero, while the correlation still shows a weak linear association.
Why least squares uses squared residuals
Ordinary least squares chooses the slope and intercept that minimize . Squaring makes each contribution nonnegative, so positive and negative residuals contribute to the total instead of canceling.
For an ordinary least-squares fit with an intercept, the residuals on the fitted observations sum to zero, using the exact coefficients. Their mean is therefore zero as well. For these data, and . That balance alone does not measure how tightly the points follow the line.