4.9.12 · D3Probability Theory & Statistics

Worked examples — Covariance and correlation

2,173 words10 min readBack to topic

The scenario matrix

Every problem below is one cell of this table. If a cell is filled, you have seen how to handle it.

Cell Relationship type What is special / degenerate Example
A Positive, non-extreme ordinary discrete joint pmf Ex 1
B Negative , deviations disagree Ex 2
C Exactly zero, linear boundary from a genuine symmetry, no dependence issue Ex 3
D Zero cov but dependent the famous trap Ex 4
E Perfect equality case of Cauchy–Schwarz Ex 5
F Perfect negative-slope exact line Ex 5
G Degenerate input one variable is a constant () — undefined! Ex 6
H Real-world, with units covariance carries kg·cm; strips units Ex 7
I Exam twist (toolbox, not sum) use bilinearity / instead of raw Ex 8

Before we compute anything, one picture to fix what the sign of covariance means geometrically — it will be our compass for the whole page.

Figure — Covariance and correlation

Example 1 — Cell A: ordinary positive relationship

  1. Marginals. Sum the joint over the other variable. , so . , so . Why this step? Expectation of a 0/1 variable is just ; we need both means before any deviation talk.

  2. . The product only when both are 1. . Why this step? is the piece our working formula needs; every other pair kills the product.

  3. Covariance. . Why this step? This is the shortcut formula from the parent — no need to build deviations by hand.

  4. Standard deviations. is Bernoulli: , . is Bernoulli: . Why this step? $\sigma$ rescales covariance into .

  5. Correlation. .

Verify: ✓, positive as forecast ✓. Sanity: if we'd loaded all mass on and we'd expect ; here the "disagree" corners still carry of the mass, so a moderate is reasonable.


Example 2 — Cell B: negative relationship

  1. Marginals. . By the symmetry of the numbers . Why this step? Same as before — get the means first.

  2. . Only contributes: .

  3. Covariance. . Why this step? Negative product-average confirms the compass: the disagree quadrants won.

  4. Correlation. Both are Bernoulli, so . .

Verify: ✓, negative ✓. Note it is the mirror image of Example 1 in the parent note (which had ): swapping the weight from agree-corners to disagree-corners flips the sign of the whole relationship.


Example 3 — Cell C: exactly zero from genuine symmetry

  1. Means. , likewise . Why this step? Symmetric values around 0 make the mean 0 — this simplifies everything.

  2. . The four products , each weight : .

  3. Covariance. .

  4. Correlation. (each variance is ), so .

Verify: ✓. Cross-check independence: equals , and similarly for all cells — so here independence genuinely holds. Contrast this with the next example.


Example 4 — Cell D: zero covariance, but fully dependent (the trap)

  1. Mean of . . Why this step? The symmetric spread makes , which will kill the correction term.

  2. . Cubes: . . Why this step? Substituting turns into a moment of alone.

  3. Covariance. .

  4. Independence check — it FAILS. Take : then with certainty, so . Knowing changes the distribution of not independent.

Verify: ✓ yet dependence is total. This is the one-way street from the parent's [!mistake] callout: independence , but independence. Covariance is blind to the symmetric (even) part of the relationship.


Example 5 — Cells E & F: the perfect-line boundary

Figure — Covariance and correlation
  1. Up-slope means. ; . Why this step? Sample correlation needs the sample means to form deviations.

  2. Deviation sums. Deviations of : ; of : (exactly the -deviations, because slope ). . ; . Why this step? — the sample version of .

  3. Up-slope . .

  4. Down-slope. Every -deviation flips sign, so while are unchanged (squares). . Why this step? This is property 5 of the toolbox: multiplying by a negative scale flips , magnitude preserved.

Verify: and ✓, both on the boundary of . This is exactly where in the Cauchy–Schwarz proof — the deviations are perfectly proportional. See Linear Regression: on a perfect line the fitted slope reproduces the data with zero error, so .


Example 6 — Cell G: degenerate input, undefined

  1. Deviation of . , so for every outcome. Why this step? A constant has zero variance — this is the degenerate feature of the cell.

  2. Covariance. . Why this step? Any factor of inside the expectation zeroes the whole thing.

  3. Correlation attempt. , so undefined (0/0, not "0").

Verify: ✓. But do not report : with the ratio is , and correlation is simply not defined when either variable is constant. This is the boundary case people silently mishandle — a constant column in data has no correlation, not "zero correlation".


Example 7 — Cell H: real-world word problem with units

  1. Means. cm; kg. Why this step? Deviations need the sample means.

  2. Deviation products. -devs: ; -devs: . . Sample covariance cm·kg. Why this step? Sample covariance uses in the denominator; the product carries mixed units.

  3. . ; . .

  4. Switch to metres. Heights divide by : by bilinearity , so sample covariance becomes m·kg. But also divides by , so in the factors cancel: stays . Why this step? Property 5 — is scale-invariant; covariance is not.

Verify: covariance cm·kg (unit-bearing) ✓; ✓. This is exactly the parent's second [!mistake]: the number covariance changed by 100× under a harmless unit change, while the strength did not budge. Always judge strength with .


Example 8 — Cell I: exam twist (use the toolbox, not the raw sum)

  1. by bilinearity. . Why this step? Toolbox property 2: shifts vanish, scales multiply out. Faster and cleaner than any computation.

  2. first. . Why this step? We need it to apply the sign rule.

  3. by scale-invariance. , so . Why this step? Property 5 — a negative scale flips the sign, magnitude preserved.

  4. . First ; . . Why this step? Property 3, the variance-of-a-sum identity; the negative covariance reduces the spread of the sum.

Verify: ; ✓; ✓ (a variance must be non-negative). Direct check of : ✓ — matches step 3.


Recall Which cell was which?

Positive ordinary ::: Ex 1 (cell A), . Negative ::: Ex 2 (cell B), . Honest zero (independent) ::: Ex 3 (cell C), AND independent. Zero-cov trap (dependent) ::: Ex 4 (cell D), but . Perfect line ::: Ex 5 (cells E,F), and . Constant input ::: Ex 6 (cell G), UNDEFINED (0/0). Units word problem ::: Ex 7 (cell H), cov changes with units, does not. Toolbox twist ::: Ex 8 (cell I), bilinearity + variance-of-sum.


Connections