Find a course

Module 6: Joint Distributions and Limit TheoremsLesson 11 of 1214 min

Joint Distributions, Covariance and Correlation

Describe two random variables with a joint table, find marginals and conditionals, and measure how they move together with covariance and correlation.

Step 1 of 13Learn

Two variables at once

So far each random variable has lived alone. Real questions usually involve several at once: a customer's age and spending, a stock's return and the market's, the temperature and the number of ice creams sold. To study them together, you need their joint distribution.

For two discrete variables, the joint PMF gives P(X = x and Y = y) for every pair. Here's an example. A store tracks whether a visitor has a loyalty card (X = 1) or not (X = 0), and how many items they buy (Y = 0, 1 or 2):

Y = 0Y = 1Y = 2Total
X = 00.200.150.050.40
X = 10.100.250.250.60
Total0.300.400.301

All six cells add to 1. The row and column totals are the marginal distributions: P(X = 1) = 0.60, and Y has marginal PMF 0.30, 0.40, 0.30. They're called marginal because they're written in the margins.

Conditional distributions come from restricting to a row or column. Given a loyalty card, P(Y = 2 | X = 1) = 0.25/0.60 ≈ 0.42. Without one, P(Y = 2 | X = 0) = 0.05/0.40 = 0.125. Card holders are more than three times as likely to buy two items.

X and Y are independent if every cell equals the product of its margins. Here P(X = 0, Y = 0) = 0.20, but P(X = 0)·P(Y = 0) = 0.40 × 0.30 = 0.12. One failing cell is enough: X and Y are dependent.

Step 2 of 13Practice · Work it out

Using the loyalty-card table, what is P(X = 1 | Y = 0), the chance a visitor who buys nothing has a card? Give a decimal to two places.

Step 3 of 13Chart

Temperature and ice creams sold

Each point is one day. The cloud slopes upward: days above average temperature tend to have above-average sales, so the covariance is positive.

Temperature and ice creams soldScatter plot with 10 points: Day 1: Temperature (°C) 14, Sales 120; Day 2: Temperature (°C) 16, Sales 150; Day 3: Temperature (°C) 18, Sales 140; Day 4: Temperature (°C) 19, Sales 190; Day 5: Temperature (°C) 21, Sales 210; Day 6: Temperature (°C) 22, Sales 200; Day 7: Temperature (°C) 24, Sales 260; Day 8: Temperature (°C) 26, Sales 250; Day 9: Temperature (°C) 28, Sales 310; Day 10: Temperature (°C) 31, Sales 330.100150200250300350101520253035SalesTemperature (°C)
Illustrative data for teaching.
Temperature and ice creams sold
PointTemperature (°C)Ice creams sold
Day 114120
Day 216150
Day 318140
Day 419190
Day 521210
Day 622200
Day 724260
Day 826250
Day 928310
Day 1031330

Step 4 of 13Learn

Covariance

To summarize how two variables move together, use the covariance:

Cov(X, Y) = E[(X − μ_X)(Y − μ_Y)] = E[XY] − E[X]·E[Y]

When X is above its mean, is Y usually above its mean too? Then the products are mostly positive and the covariance is positive. If high X tends to go with low Y, it's negative. If there's no linear tendency either way, it's near zero.

Loyalty-card example.

  • E[X] = 0.60 (from the margin).
  • E[Y] = 0(0.30) + 1(0.40) + 2(0.30) = 1.00.
  • E[XY]: only cells with X = 1 and Y ≥ 1 contribute: 1·1·0.25 + 1·2·0.25 = 0.75.
  • Cov(X, Y) = 0.75 − 0.60 × 1.00 = 0.15.

Positive, as expected: card holders buy more.

Covariance completes the rule for adding variances. For any X and Y:

Var(X + Y) = Var(X) + Var(Y) + 2·Cov(X, Y)

Independent variables have covariance 0, which recovers the earlier rule. Positively related variables make sums more variable; negatively related ones make sums less variable. That's the logic of hedging: pairing an investment with one that tends to move the opposite way reduces the total risk.

The downside of covariance is its units. Measure spending in cents instead of dollars and the covariance becomes 100 times larger, though the relationship hasn't changed.

Step 5 of 13Practice · Work it out

X and Y have Var(X) = 4, Var(Y) = 9 and Cov(X, Y) = −3. What is Var(X + Y)?

Step 6 of 13Learn

Correlation

Correlation rescales covariance so it has no units and always lies between −1 and 1:

ρ = Corr(X, Y) = Cov(X, Y) / (σ_X · σ_Y)

  • ρ = 1: perfect increasing linear relationship (Y = a + bX with b > 0).
  • ρ = −1: perfect decreasing linear relationship.
  • ρ = 0: no linear relationship.

For the loyalty card: Var(X) = 0.60 × 0.40 = 0.24, and Var(Y) = E[Y2] − 12 = (0.40 + 4 × 0.30) − 1 = 0.60. So ρ = 0.15 / √(0.24 × 0.60) ≈ 0.15 / 0.379 ≈ 0.40, a moderate positive association.

Three warnings come with every correlation:

  1. Correlation is not causation. Cities with more firefighters have more fire damage, because big fires bring more firefighters. Hidden third variables (confounders) often drive both.
  2. Zero correlation does not mean independence. Let X be −1, 0 or 1 with equal probability, and Y = X2. Y is completely determined by X, yet Cov(X, Y) = E[X3] − E[X]E[X2] = 0 − 0 = 0. Correlation detects only straight-line patterns.
  3. Correlation is sensitive to outliers and to the range of data. Restricting to a narrow range, such as only top students, can make a real relationship look weak.

Independence does guarantee zero correlation. The reverse holds only in special cases, most notably when X and Y are jointly normal.

Step 7 of 13Practice · Diagram

Reading a correlation

Which pair has the weakest linear relationship?

Tap the shape that answers the question, then press Check.

Reading a correlationScale: Car age and resale price, Shoe size and exam score, Height and weight.Strong negativeWeak or noneStrong positive-1-0.75-0.5-0.2500.250.50.751-0.8Car age and resaleprice0.02Shoe size and examscore0.7Height and weight
Marker positions are typical illustrative values, not measured figures.
Car age and resale price

Older cars sell for less: a strong negative linear link.

Shoe size and exam score

Essentially no linear relationship among adults.

Height and weight

Taller people tend to weigh more, with plenty of scatter.

Step 8 of 13Practice · True or false

If Cov(X, Y) = 0, then X and Y must be independent.

Step 9 of 13Note

Step 10 of 13Practice · Chart

50/50 portfolio risk as correlation changes

Two assets, each with SD 20%. The lower the correlation, the more their ups and downs cancel.

Tap the correlation that removes all the risk.

Tap the bar that answers the question, then press Check.

50/50 portfolio risk as correlation changesBar chart with 5 categories: ρ = 1: 20%; ρ = 0.5: 17.3%; ρ = 0: 14.1%; ρ = −0.5: 10%; ρ = −1: 0%.0%5%10%15%20%ρ = 1ρ = 0.5ρ = 0ρ = −0.5ρ = −120%17.3%14.1%10%0%
50/50 portfolio risk as correlation changes
ItemPortfolio SD
ρ = 120%
ρ = 0.517.3%
ρ = 014.1%
ρ = −0.510%
ρ = −10%

Step 11 of 13Try the calculator

Portfolio risk calculator

Two assets with return SDs σ₁ and σ₂, correlation ρ, and weight w in the first asset.

Portfolio SD
16.12 %
Covariance
120 %²

Step 12 of 13Practice · Select all that apply

Which statements about covariance and correlation are true?

Select all that apply.

Step 13 of 13Practice · Choose one

X and Y have SDs 2 and 5 and covariance 6. What is their correlation?