4.9.12 · D2Probability Theory & Statistics

Visual walkthrough — Covariance and correlation

1,898 words9 min readBack to topic

We work with two numbers measured on the same object — say height and weight of a person. Each person is one dot on a graph: horizontal position , vertical position .


Step 1 — Plot the cloud of dots

WHAT. We collect many pairs and drop each as a dot. This picture is a scatter plot.

WHY. Before any formula, we need to see the raw question: "when is large, does tend to be large too?" A cloud that slopes up-right says yes; a cloud sloping down says opposite; a shapeless blob says no pattern. Everything below is just a way to turn this visual slope into one number.

PICTURE. Look at the up-right tilt of the blue cloud below.

Figure — Covariance and correlation

Step 2 — Find each variable's balance point

WHAT. Compute and — the average of all horizontal positions and the average of all vertical positions. Draw the two lines (vertical) and (horizontal).

WHY. "High" and "low" are meaningless until we pick a reference. The mean is the fairest reference: it is the point about which the dots balance. These two lines chop the plane into four rooms (quadrants) that we will label with signs next.

PICTURE. The orange crosshair is the pair — the centre of mass of the cloud.

Figure — Covariance and correlation


Step 3 — Measure each dot as a deviation from the centre

WHAT. For a dot at , form its two deviations:

WHY. Absolute positions don't tell us "agreement". Relative to the centre does: a dot to the right of centre has ; to the left, . Same idea vertically. This is exactly the raw material of Variance and Standard Deviation — there we squared one deviation; here we will pair two.

PICTURE. The green arrow is the horizontal deviation, the red arrow the vertical deviation, measured from the orange centre to the dot.

Figure — Covariance and correlation

Step 4 — Multiply the two deviations: a sign for each room

WHAT. For each dot compute the product .

WHY. We want one operation that says + for agreement, − for disagreement. Multiplication is the cheapest such operation, because "same sign × same sign = +" and "opposite signs = −". Walk the four rooms:

  • Top-right (right and up): — they agree (both above average).
  • Bottom-left (left and down): — they agree (both below average).
  • Top-left (left, up): — disagreement.
  • Bottom-right (right, down): — disagreement.

So the product's sign is a vote: vote for "move together", vote for "move apart". Its size is how emphatic that dot's vote is (a dot far out in a corner votes loudly).

PICTURE. Each room is shaded by the sign of the product; agreement rooms green , disagreement rooms red .

Figure — Covariance and correlation

Step 5 — Average the votes: this IS covariance

WHAT. Take the expectation (average) of all those signed products:

WHY. Averaging lets the green votes and red votes cancel or dominate. Net positive ⇒ the cloud leans up-right (they move together). Net negative ⇒ it leans down-right. Near zero ⇒ no linear tilt. This one number is the whole story of Step 1's picture.

PICTURE. Three clouds side by side: positive covariance (up-tilt), zero (round blob), negative (down-tilt) — with each cloud's net vote shown.

Figure — Covariance and correlation

Step 6 — The units problem: why covariance can't measure strength

WHAT. Stretch the whole cloud horizontally by a factor (measure height in millimetres instead of centimetres). The tilt looks the same, but the covariance number multiplies by .

WHY. From bilinearity, . So a bigger number need not mean a stronger relationship — it might just mean bigger units. We need to divide out each variable's own spread.

PICTURE. Same-shaped cloud, x-axis relabelled — covariance jumps from to with zero change in the pattern.

Figure — Covariance and correlation

Step 7 — Put covariance on a leash: correlation

WHAT. Define

WHY. Dividing by rescales the horizontal spread to , and by the vertical spread to . The stretched and unstretched clouds now look identical — and give the same . So is a unitless score of pattern shape only, immune to Step 6's trick.

PICTURE. After standardising each axis, the cloud fits inside a box; the tilt of the best-fit line is what reports.

Figure — Covariance and correlation

Step 8 — Why can never leave (the leash proof, seen)

WHAT. Let , . For any real slope , the quantity is an average of squares, so it is :

WHY. A quadratic in that never dips below can touch the axis at most once — its discriminant must be : This is exactly the Cauchy–Schwarz Inequality. Equality () happens only when some makes , i.e. with no scatter is an exactly straight line in .

PICTURE. The parabola sitting on or above the axis; when it just kisses the axis, .

Figure — Covariance and correlation

Step 9 — The degenerate cases you must never be ambushed by

WHAT & WHY. Four edge scenarios, each with what does:

  • Perfect line, up: all dots on a rising straight line ⇒ (parabola in Step 8 touches axis at ).
  • Perfect line, down: falling straight line ⇒ .
  • Flat / vertical cloud: if never varies then , and is undefined — there is no "tilt" to report.
  • Curved but symmetric, e.g. with symmetric about : the green and red votes cancel exactly, so and even though is fully determined by . Covariance sees only the linear part of a relationship. This is why does not imply Independence of Random Variables.

PICTURE. The four cases in one strip, each labelled with its .

Figure — Covariance and correlation

The one-picture summary

Everything compressed: dots → deviations from the mean → signed products (green agree, red disagree) → average them (covariance) → divide by spreads to get the leashed score .

Figure — Covariance and correlation
Recall Feynman: the whole walkthrough in plain words

Picture two friends on swings, each dot a snapshot in time. First we find each friend's middle position — their balance point. Then for every snapshot we ask two yes/no-ish questions: "is friend ahead of their middle?" and "is friend ahead of theirs?" We multiply the two answers so that both-ahead or both-behind scores , and one-ahead-one-behind scores . Averaging all those little scores is covariance: a big means great teamwork, a big means they mirror each other, near means no pattern. But "how big" the score is depends on how wildly each friend swings, which is unfair for comparing pairs of friends. So we divide by each one's typical swing size — that squeezes the score onto a fixed report card from (perfect opposites) through (no teamwork) to (perfect together). That report card is correlation, and a beautiful square-is-never-negative argument (Cauchy–Schwarz) guarantees the score can never escape the to leash. The only way to hit the very ends is for the dots to lie on a perfectly straight line.


Active recall

Which room of the crosshair gives ?
Bottom-left — both variables below their means, still an agreement vote.
Why divide covariance by ?
To cancel units and rescale, giving a pattern-only score bounded in .
In Step 8, why must the discriminant be ?
The quadratic is for all , so it can't have two real roots.
When is undefined?
When or (a variable never varies), giving .
Give a case with but full dependence.
with symmetric about : agree/disagree votes cancel, yet is fixed by .

Connections