1.3.9 · D4Probability & Statistics

Exercises — Covariance and correlation

2,313 words11 min readBack to topic

This page is your self-test dojo for the parent topic. Work each problem before opening the solution. Every symbol below was built in the parent note — if a piece feels shaky, revisit 1.3.05-Expectation-and-variance (means, variance) and 1.3.08-Joint-and-marginal-distributions (joint tables) first.

Quick reminder of the tools we keep reusing (all proven in the parent):


Level 1 — Recognition

L1.1 — Sign of a relationship

A scatter cloud of points slopes downhill from top-left to bottom-right (as grows, shrinks). Is positive, negative, or zero?

Recall Solution

What we look at: the direction of the trend, not its steepness. Downhill means: when is above its mean, tends to be below its mean. So the product is (positive)×(negative) = negative for most points. Averaging many negative products gives a negative number. Answer: negative covariance. The figure below makes all three signs visible side by side.

The figure below shows three scatter clouds. Left (pink): negative covariance — the pink points and the pink arrow slope downhill, matching this problem. Middle (blue): near-zero covariance — a shapeless cloud with no tilt. Right (yellow): positive covariance — points climb uphill. Compare the tilt direction, not the spread, to read the sign.

Figure — Covariance and correlation

L1.2 — Which quantity is unit-free?

You measure covariance and correlation between height (metres) and weight (kg). One of these numbers would change if you switched height to centimetres. Which one stays the same?

Recall Solution

Covariance carries units of (metre·kg). Switch metres→centimetres and every gets multiplied by , so covariance scales by . Correlation divides by , and also scales by . The two 100's cancel. Answer: correlation is unchanged (dimensionless). Covariance changes.


Level 2 — Application

L2.1 — Covariance from a joint table

0 1 0.3
0 3 0.2
2 1 0.1
2 3 0.4

Compute .

Recall Solution

Step 1 — marginal means. Group the probabilities by each value. Why: a marginal mean sums a variable's value against all joint rows containing it.

Step 2 — the cross term . Multiply by its probability, then sum.

Step 3 — assemble. Interpretation: positive — and lean upward together.

L2.2 — Sample correlation from four points

Data: . Find the sample correlation .

Recall Solution

Step 1 — means. , .

Step 2 — deviations and products.

product
1 3
2 3
3 5
4 5

Sums: , , .

Step 3 — why the disappears. The full sample formula would divide the numerator sum by and each variance sum by too. Writing : The in the denominator exactly cancels the on top. So depends only on the raw sums: Interpretation: strong positive — but not perfect, because stays flat while moves inside each pair.


Level 3 — Analysis

L3.1 — Rescaling and shifting

You already found in L2.1. Now define and . What is , and what is compared with ?

Recall Solution

Rule (from linearity): additive constants shift the mean but not the deviations, so they drop out. Multiplicative constants pull straight out: Apply: : Correlation: standard deviations scale by and : Here , so . The +7 and +1 do nothing; only the sign flips.

L3.2 — Reading a correlation off a line

Points lie exactly on the line . Without a table, state and justify.

Recall Solution

Key fact: correlation exactly when all points sit on one straight line. The sign matches the slope's sign. Here the slope , so .

Heuristic proof (why a perfect line forces ): write with . Then , so each -deviation is a scaled copy of the -deviation: Substitute into the formula: The cancels top and bottom, and . So the size of leaves no trace — only its sign survives.

Why the slope's size doesn't matter: correlation measures how tightly points hug a line, not how steep the line is. Perfect hug ⇒ regardless of slope (as long as slope ).


Level 4 — Synthesis

L4.1 — Correlation of a sum with a part

Let and be independent with . Define . Find .

Recall Solution

Step 1 — covariance splits over sums. Because covariance is linear in each slot: Now , and independence gives (see 1.2.04-Independence). So .

Step 2 — variance of . For independent parts variances add: And .

Step 3 — assemble. Interpretation: makes up "half the ingredients" of , so they share a moderate positive correlation, not a perfect one — the noise dilutes it.

L4.2 — Building a covariance matrix

For the same (independent, unit variance) and , write the covariance matrix of the vector .

Recall Solution

Layout: the covariance matrix has variances on the diagonal, covariances off-diagonal: Plug in , (from L4.1), , and by symmetry: Why symmetric? always — swapping the two factors inside changes nothing. This matrix is exactly what 2.4.01-Principal-component-analysis eigen-decomposes.


Level 5 — Mastery

L5.1 — Prove zero correlation need not mean independence

Let take values each with probability , and set . Show , then show and are not independent.

Recall Solution

Step 1 — the means. Step 2 — the cross term. , so : Step 3 — covariance. So they are uncorrelated.

Step 4 — but not independent. Independence demands for all pairs. Test : Since , they are dependent. Knowing tells you for certain — total information, yet zero linear correlation. This is why 4.1.03-Feature-selection cannot rely on correlation alone to drop features.

L5.2 — Derive that forces a straight line

Using standardized variables and (each mean , variance ), show that if then is an exact increasing linear function of .

Recall Solution

Step 1 — build a clever non-negative quantity. Consider the variance of the difference: Step 2 — substitute knowns. Each standardized variable has variance , and . So: Step 3 — set . Then . A random variable with zero variance is constant (equal to its mean, which is ). Therefore: Step 4 — solve for . a straight line with positive slope . (Repeating with uses , giving — a line of negative slope.)


Recall Self-check ledger (answers only)

L1.1 negative ::: negative covariance L1.2 which is unit-free ::: correlation L2.1 covariance ::: L2.2 correlation ::: L3.1 Cov(U,V) ::: L3.2 correlation ::: L4.1 ::: L5.1 covariance ::: (but dependent)