Actuarial Statistics · Exploratory data analysis
Correlation and Scatterplots: Pearson and Spearman Explained
Updated 11 October 2026 · Fact-checked
Correlation measures how strongly two variables move together. Plot a scatterplot first. Then compute sxx, syy and sxy from the data. Pearson r = sxy ÷ √(sxx × syy) measures linear association. Spearman's coefficient applies the same formula to ranks, so it measures monotonic association and handles ties by average ranks.
Understand Correlation and Scatterplots
A scatterplot puts one variable on the x-axis and the other on the y-axis, one point per observation. It shows direction (upward or downward), form (straight line or curve), strength (tight or scattered) and outliers. Always look at it before you calculate anything.
Covariance measures whether x and y tend to be above their means together. If large x goes with large y, the products (x − x̄)(y − ȳ) are mostly positive and the covariance is positive. If large x goes with small y, it is negative. The size of covariance depends on units, so it is hard to interpret on its own.
Pearson's correlation coefficient r divides the covariance by both standard deviations. This removes the units and forces −1 ≤ r ≤ 1. A value near +1 or −1 means the points lie close to a straight line. A value near 0 means no linear relationship. It does not rule out a curved relationship.
Spearman's rank correlation replaces each value by its rank (1 for the smallest) and then calculates the Pearson coefficient on the ranks. It measures how well the relationship follows a monotonic pattern, one that always rises or always falls. It is less affected by outliers and by skewed data, and it works for ordinal data.
Correlation shows association, not cause. Two variables can be strongly correlated because of a third variable, or by chance in a small sample.
Key rules to remember
- Sums of squares and products
- sxx = Σx² − (Σx)² ÷ n; syy = Σy² − (Σy)² ÷ n; sxy = Σxy − (Σx)(Σy) ÷ n
- Equivalent to Σ(x − x̄)², Σ(y − ȳ)² and Σ(x − x̄)(y − ȳ). Use these for fast calculator work.
- Sample covariance
- sample covariance = sxy ÷ (n − 1)
- Some texts divide by n. State which one you use. The correlation does not change, because the divisor cancels.
- Pearson correlation coefficient
- r = sxy ÷ √(sxx × syy)
- Always between −1 and 1. Unchanged if you add a constant to the data or multiply by a positive constant. Measures linear association only.
- Coefficient of determination (simple linear regression)
- R² = r²
- Proportion of variation in y explained by the fitted straight line on x.
- Spearman rank correlation (general)
- ρ = Pearson correlation of the ranks = sRxRy ÷ √(sRxRx × sRyRy)
- Valid with or without ties. Tied values get the average of the ranks they occupy.
- Spearman shortcut (no ties)
- ρ = 1 − 6 Σd² ÷ (n(n² − 1)), where d = rank of x − rank of y
- Exact only when there are no ties. With a few ties it is only approximate.
How to solve Correlation and Scatterplots questions
Use this order for any correlation question, whether it asks for a calculation, an interpretation or a comparison of methods.
- 1Read what is asked: Pearson or Spearman, covariance or correlation, and whether n or n − 1 is expected.
- 2Sketch or describe the scatterplot if data are given. Note direction, shape and any outlier.
- 3For Pearson, compute n, Σx, Σy, Σx², Σy² and Σxy. Then find sxx, syy and sxy.
- 4Calculate r = sxy ÷ √(sxx × syy). Check that it lies between −1 and 1 and that its sign matches the sign of sxy.
- 5For Spearman, rank x and y separately from smallest to largest. Give tied values the average rank. Then apply the Pearson method to the ranks, or the shortcut if there are no ties.
- 6Interpret in words: direction, strength, and whether it is linear (Pearson) or monotonic (Spearman).
- 7Add a caution: correlation is not causation, and the sample size or outliers may affect reliability.
Quickest way: Table of sums, then one division
When to use it: Use this for any Pearson calculation in a timed paper with a calculator.
- Set up columns x, y, x², y², xy and add the totals. Do not compute deviations from the mean for each row.
- Compute sxy, sxx and syy using the sum formulas. Keep full calculator accuracy until the end.
- Find r = sxy ÷ √(sxx × syy) in one calculator line.
- For Spearman, use the calculator's statistics mode on the ranks, or compute sums of the ranks the same way.
- Check the sign, and check that |r| ≤ 1. If not, you have an arithmetic slip, usually in Σxy or in a squared sum.
Common mistakes in Correlation and Scatterplots
Using (Σx)² as Σx² (or the reverse) in sxx.
The two sums look alike and both appear in the formula.
Fix: Write Σx² (square each value, then add) and (Σx)² (add, then square) as separate lines in your table.
Getting r outside the range −1 to 1, or a negative sxx.
An arithmetic error in the sums. sxx and syy must always be zero or positive.
Fix: Check sxx ≥ 0 and syy ≥ 0 before dividing. Recompute the sums if either fails.
Ranking x and y together instead of separately.
Students treat the data as one list.
Fix: Make two rank columns. Rank x among the x-values only and y among the y-values only.
Giving tied values consecutive ranks, such as 2 and 3, instead of the average.
Students rank by position in the sorted list.
Fix: If two values tie for ranks 2 and 3, give both 2.5. The ranks used must still add up to n(n + 1) ÷ 2.
Using the 1 − 6Σd² shortcut when there are ties and presenting it as exact.
It is the formula most students remember.
Fix: With ties, compute the Pearson correlation of the ranks. If you use the shortcut, say it is approximate.
Concluding that r near 0 means the variables are unrelated, or that a high r means one causes the other.
Treating r as a measure of any relationship rather than a linear one.
Fix: Say r near 0 means no linear association, and note that a curved relationship may exist. Say correlation does not prove causation.
Worked examples
Example 1
For five observations, x = 1, 2, 3, 4, 5 and y = 2, 4, 5, 4, 5. Calculate sxx, syy, sxy and the Pearson correlation coefficient r.
Show the solution
- n = 5. Σx = 15. Σy = 2 + 4 + 5 + 4 + 5 = 20.
- Σx² = 1 + 4 + 9 + 16 + 25 = 55. Σy² = 4 + 16 + 25 + 16 + 25 = 86.
- Σxy = 1×2 + 2×4 + 3×5 + 4×4 + 5×5 = 2 + 8 + 15 + 16 + 25 = 66.
- sxx = 55 − 15² ÷ 5 = 55 − 45 = 10.
- syy = 86 − 20² ÷ 5 = 86 − 80 = 6.
- sxy = 66 − (15 × 20) ÷ 5 = 66 − 60 = 6.
- r = 6 ÷ √(10 × 6) = 6 ÷ √60 = 6 ÷ 7.7460 = 0.7746.
Answer: sxx = 10, syy = 6, sxy = 6 and r ≈ 0.775. This is a fairly strong positive linear association.
Example 2
Two judges score five candidates. Judge A's scores are 10, 20, 20, 30, 40. Judge B's scores for the same candidates, in the same order, are 5, 8, 6, 6, 9. Calculate Spearman's rank correlation coefficient, allowing for ties.
Show the solution
- Rank A: 10 → 1. The two 20s share ranks 2 and 3, so each gets 2.5. 30 → 4. 40 → 5. In candidate order the ranks are 1, 2.5, 2.5, 4, 5.
- Rank B: 5 → 1. The two 6s share ranks 2 and 3, so each gets 2.5. 8 → 4. 9 → 5. In candidate order (5, 8, 6, 6, 9) the ranks are 1, 4, 2.5, 2.5, 5.
- Both rank totals are 15, so both mean ranks are 3.
- Deviations of A ranks from 3: −2, −0.5, −0.5, 1, 2. Deviations of B ranks from 3: −2, 1, −0.5, −0.5, 2.
- sRaRa = 4 + 0.25 + 0.25 + 1 + 4 = 9.5. sRbRb = 4 + 1 + 0.25 + 0.25 + 4 = 9.5.
- sRaRb = (−2)(−2) + (−0.5)(1) + (−0.5)(−0.5) + (1)(−0.5) + (2)(2) = 4 − 0.5 + 0.25 − 0.5 + 4 = 7.25.
- ρ = 7.25 ÷ √(9.5 × 9.5) = 7.25 ÷ 9.5 = 0.7632.
- Check: the no-ties shortcut gives Σd² = 4.5, so 1 − 27 ÷ 120 = 0.775. It is close but not exact, because of the ties.
Answer: Spearman's ρ ≈ 0.763, showing a fairly strong positive monotonic agreement between the two judges.
Exam tips
- Show the sums (n, Σx, Σy, Σx², Σy², Σxy) clearly. Method marks are usually given even if the final r is slightly off.
- When asked to compare Pearson and Spearman, state three points: Pearson is for linear relationships and is sensitive to outliers, Spearman is for monotonic relationships and is based on ranks, and Spearman can be used for ordinal data.
- For tied data, show the average ranks in a table. Then compute the Pearson correlation of the ranks, and mention that the shortcut formula is only approximate.
- In interpretation parts, write one sentence on direction, one on strength and one caution about causation or outliers.
- In the computer-based Paper B, state the R function you used and report the coefficient with the method (for example cor with method set to pearson or spearman), as well as the value.
Practice questions from Exploratory data analysis
- A scatterplot of monthly premium income (x, in ₹ lakh) against claims (y, in ₹ lakh) for a Mumbai insurer gives r = 0.80. Every x value is t…
- A researcher has data on monthly premium income of 5 branches of an Indian insurer observed every month for 24 months. How should this datas…
- Twenty-one observations of claim size are ordered. Using the convention that the p-th quantile lies at position p(n+1), what is the lower qu…
- A sample of 5 monthly claim counts is 4, 6, 8, 10, 12. What is the sample variance, using divisor n-1?
- A normal Q-Q plot of residuals from a claims model shows points that follow the reference line in the middle but curve sharply upwards at th…
Correlation and Scatterplots: frequently asked questions
What is the difference between Pearson and Spearman rank correlation?
Pearson correlation measures the strength of a straight-line relationship using the actual values. Spearman correlation uses ranks, so it measures whether the relationship is consistently rising or falling, even if curved. Spearman is less affected by outliers and can be used with ordinal data.
How do I calculate the correlation coefficient using sxx, sxy and syy?
Compute sxx = Σx² − (Σx)²/n, syy = Σy² − (Σy)²/n and sxy = Σxy − (Σx)(Σy)/n. Then r = sxy ÷ √(sxx × syy). The result must lie between −1 and 1.
How do I handle ties in Spearman's rank correlation?
Give each tied value the average of the ranks they would have occupied. Then calculate the Pearson correlation of the two sets of ranks. The 1 − 6Σd²/(n(n² − 1)) formula is exact only without ties.
Does a correlation of zero mean there is no relationship?
No. It means there is no linear relationship (for Pearson). The variables can still be strongly related in a curved way, for example y = x² with x symmetric about zero. Always check the scatterplot.