📘 CodingMarble Learn

Correlation: Scatter Diagram, Karl Pearson's Coefficient and Spearman's Rank Correlation

Correlation tells how two variables move together. It is positive when both rise together, negative when one rises as the other falls, and zero when there is no straight-line pattern. A scatter diagram shows it as a picture. Karl Pearson's coefficient r measures its direction and strength and always lies between −1 and +1. Spearman's rank correlation R uses ranks and works for qualities like beauty or honesty; tied ranks need a small correction.

🎬 Step-by-step story

  1. Each dot is a month. As the price rose, the quantity supplied rose too. The dots climb up and to the right: positive correlation.
  2. As price rose, demand fell: the dots slide down, negative correlation. Shoe size and marks give scattered dots: no correlation.
  3. The coefficient r always sits between −1 and +1. At ±1 all dots lie on one straight line. At 0 there is no straight-line link.
  4. Karl Pearson's r: each dot forms a rectangle of dx times dy. Green areas add, red areas subtract. Here r = 6 ÷ √60 ≈ 0.77.
  5. Spearman's rank: two judges rank five dancers. Square each rank difference. R = 1 − 6ΣD² ÷ (n³ − n) = 0.8.
  6. Free play: bend the cloud of dots with the slider and watch r change live.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

What does a positive correlation look like?

Dots climbing from bottom-left to top-right.

If two things are correlated, does one cause the other?

Not necessarily. Both may depend on a third factor, or it may be chance.

Can r be 1.2?

Never. r is always between −1 and +1. A value outside means a calculation mistake.

Why do we multiply dx and dy?

If both are above (or both below) their means, the product is positive and pushes r up; opposite signs push it down.

What do I do with tied ranks?

Give each the average rank, then add (m³ − m) ÷ 12 for each tie group to ΣD².

Does r = 0 mean no relation at all?

It means no straight-line relation. A curved relation can still exist.

Meaning of correlation

Correlation studies how two variables change together. It tells the direction (same or opposite) and strength (how closely) of the relationship.

Correlation is not causation. Two things can move together by chance or because of a third factor. Ice-cream sales and sunburn both rise in summer; one does not cause the other.

Scatter diagram

Plot each pair (x, y) as a dot. The pattern tells the kind of correlation:

It is quick and visual but gives no exact number.

Karl Pearson's coefficient of correlation (ungrouped data)

r = Σdxdy ÷ √(Σdx² × Σdy²), where dx = x − x̄ and dy = y − ȳ (actual mean method).

Other forms:

Why it works: when both deviations have the same sign, dx·dy is positive (green rectangles). When they have opposite signs, it is negative (red). The sum decides the sign of r.

Properties of r

Spearman's rank correlation

Used when data are ranks, or qualities that cannot be measured (beauty, honesty), or when there are extreme values.

Non-repeated ranks

R = 1 − 6ΣD² ÷ (n³ − n), where D = difference between the two ranks of an item and n = number of pairs. Steps: give ranks (largest = 1 if not given), find D, square, add, put in the formula. Check: ΣD = 0.

Repeated (tied) ranks

When values tie, give each the average of the ranks they would take. Two items sharing 3rd and 4th place each get 3.5. Then add a correction for every tie group of size m:

R = 1 − 6[ΣD² + Σ(m³ − m) ÷ 12] ÷ (n³ − n).

R also lies between −1 and +1. Spearman's R and Pearson's r are equal when there are no ties and ranks are used as data.

Try it: are height and shoe size linked?

Measure the height and shoe size of 6 people at home. Plot them as dots on graph paper. Do the dots rise? Then rank the 6 by height and by shoe size and find Spearman's R. Finally, on the last 3D step, move the slider until the dots look like yours and read r.

Board exam pattern

Expect a 4 or 6-mark numerical on Karl Pearson's r (often by the actual mean or step deviation method), a 3 or 4-mark Spearman's R with ties, and short questions on properties and scatter diagrams. Show the full table: x, y, dx, dy, dx², dy², dxdy.

Key formulas and definitions

Worked examples

1. x: 1, 2, 3, 4, 5 and y: 2, 4, 5, 4, 5. Find Karl Pearson's r.

x̄ = 3, ȳ = 4. dx: −2, −1, 0, 1, 2; dy: −2, 0, 1, 0, 1. Σdxdy = 4 + 0 + 0 + 0 + 2 = 6. Σdx² = 10, Σdy² = 6. r = 6 ÷ √60 = 6 ÷ 7.746 ≈ 0.77.

2. x: 2, 4, 6, 8 and y: 9, 7, 5, 3. Find r.

x̄ = 5, ȳ = 6. dx: −3, −1, 1, 3; dy: 3, 1, −1, −3. Σdxdy = −9 − 1 − 1 − 9 = −20. Σdx² = 20, Σdy² = 20. r = −20 ÷ 20 = −1 (perfect negative).

3. x: 10, 20, 30 and y: 5, 15, 10. Find r by the direct formula.

n = 3, Σx = 60, Σy = 30, Σxy = 50 + 300 + 300 = 650, Σx² = 1400, Σy² = 350. r = (3 × 650 − 60 × 30) ÷ √[(4200 − 3600)(1050 − 900)] = 150 ÷ √(600 × 150) = 150 ÷ 300 = 0.5.

4. Two judges rank 5 dancers: A: 1, 2, 3, 4, 5; B: 2, 1, 4, 3, 5. Find R.

D: −1, 1, −1, 1, 0; ΣD² = 4. R = 1 − 6 × 4 ÷ (125 − 5) = 1 − 24 ÷ 120 = 0.8.

5. Marks in Economics: 50, 60, 60, 70 and in Maths: 30, 45, 40, 50. Find Spearman's R.

Economics ranks (largest = 1): 70 → 1, 60 and 60 share 2 and 3 → 2.5 each, 50 → 4. So ranks: 4, 2.5, 2.5, 1. Maths ranks: 50 → 1, 45 → 2, 40 → 3, 30 → 4, so 4, 2, 3, 1. D: 0, 0.5, −0.5, 0; ΣD² = 0.5. One tie with m = 2: (8 − 2) ÷ 12 = 0.5. R = 1 − 6(0.5 + 0.5) ÷ (64 − 4) = 1 − 6 ÷ 60 = 0.9.

6. r between x and y is 0.6. What is r if every x is multiplied by 10 and 5 is added to every y?

Still 0.6. r does not change with change of origin or (positive) change of scale.

Common mistakes

Practice quiz

1. Price and quantity demanded usually show:
2. The value of r lies between:
3. Spearman's method is best for:
4. Changing the origin of data changes r:
5. If all dots lie on a rising straight line, r =

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is the formula for Karl Pearson's coefficient of correlation?

r = Σdxdy ÷ √(Σdx² × Σdy²), where dx and dy are deviations from the means.

What is Spearman's rank correlation formula?

R = 1 − 6ΣD² ÷ (n³ − n); with ties, add Σ(m³ − m)/12 to ΣD².

What are the types of correlation?

Positive, negative and zero; also perfect or partial, high or low, depending on strength.

Where this is taught

Canada (Ontario)Grade 12D. Data Management
Canada (Ontario)Grade 12D. Statistical Analysis
ItalySecondaria di secondo grado – classe 3ªData and prediction
ItalySecondaria di secondo grado – classe 4ªData and prediction
Spain4º ESOStochastic sense
Spain4º ESOStochastic sense
Spain1º BachilleratoStochastic Sense
Spain1º BachilleratoStochastic Sense
Spain1º BachilleratoStochastic sense
CBSE (India)Class 11Descriptive Statistics
CBSE (India)Class 11Statistical Tools and Interpretation
England (GCSE, A level)Year 112. Processing, representing and analysing data (part 2)
England (GCSE, A level)Year 13L-M Data and conditional probability
USA (Common Core, NGSS, AP)Grade 9Descriptive statistics
USA (Common Core, NGSS, AP)Grade 9Descriptive statistics
USA (Common Core, NGSS, AP)Grade 12Regression Analysis
South Korea고등학교 2학년Modelling and evaluation
Russia11 классCorrelation
China高三Ch.8 Paired data

Learn first

Learn next

Related lessons

All Economics lessons