Worked examples — Covariance and correlation
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.

Example 1 — Cell A: ordinary positive relationship
-
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.
-
. The product only when both are 1. . Why this step? is the piece our working formula needs; every other pair kills the product.
-
Covariance. . Why this step? This is the shortcut formula from the parent — no need to build deviations by hand.
-
Standard deviations. is Bernoulli: , . is Bernoulli: . Why this step? $\sigma$ rescales covariance into .
-
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
-
Marginals. . By the symmetry of the numbers . Why this step? Same as before — get the means first.
-
. Only contributes: .
-
Covariance. . Why this step? Negative product-average confirms the compass: the disagree quadrants won.
-
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
-
Means. , likewise . Why this step? Symmetric values around 0 make the mean 0 — this simplifies everything.
-
. The four products , each weight : .
-
Covariance. .
-
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)
-
Mean of . . Why this step? The symmetric spread makes , which will kill the correction term.
-
. Cubes: . . Why this step? Substituting turns into a moment of alone.
-
Covariance. .
-
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

-
Up-slope means. ; . Why this step? Sample correlation needs the sample means to form deviations.
-
Deviation sums. Deviations of : ; of : (exactly the -deviations, because slope ). . ; . Why this step? — the sample version of .
-
Up-slope . .
-
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
-
Deviation of . , so for every outcome. Why this step? A constant has zero variance — this is the degenerate feature of the cell.
-
Covariance. . Why this step? Any factor of inside the expectation zeroes the whole thing.
-
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
-
Means. cm; kg. Why this step? Deviations need the sample means.
-
Deviation products. -devs: ; -devs: . . Sample covariance cm·kg. Why this step? Sample covariance uses in the denominator; the product carries mixed units.
-
. ; . .
-
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)
-
by bilinearity. . Why this step? Toolbox property 2: shifts vanish, scales multiply out. Faster and cleaner than any computation.
-
first. . Why this step? We need it to apply the sign rule.
-
by scale-invariance. , so . Why this step? Property 5 — a negative scale flips the sign, magnitude preserved.
-
. 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
- Covariance and Correlation — this page is its worked-example companion.
- Expectation of Random Variables — every mean and here.
- Variance and Standard Deviation — the 's that rescale, and the degenerate case.
- Independence of Random Variables — Ex 3 (genuine) vs Ex 4 (fails).
- Cauchy–Schwarz Inequality — the boundary in Ex 5.
- Linear Regression — perfect line ⇒ .
- Covariance Matrix — Ex 8's toolbox scales to whole random vectors.