Week 3.3: Covariance & Correlation
601 words
3 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Week 3.3: Covariance & Correlation > **Prerequisites:** Expectation ([Week 3.1: Expected Value](/notes/01-foundation-bsma1004-stats-2-week03-08-expectation)), Variance ([Week 3.2: Variance & Standard Deviation](/notes/01-foundation-bsma1004-stats-2-week03-09-variance)), Independence ([Week 2.3: Independence of Ran...

Week 3.3: Covariance & Correlation
Prerequisites: Expectation (Week 3.1: Expected Value), Variance (Week 3.2: Variance & Standard Deviation), Independence (Week 2.3: Independence of Random Variables) Cross-links: BSMA3012 (Linear Stat Models) — covariance matrix Core question: How do two random variables vary together?
1. Intuition: The Co-variation
Two RVs can have the same individual means and variances yet completely different relationships:
| Y\X | 0 | 1 |
|---|---|---|
| 0 | 1/4 | 1/4 |
| 1 | 1/4 | 1/4 |
Independent: Cov(X,Y)=0.
| Y\X | 0 | 1 |
|---|---|---|
| 0 | 0 | 1/2 |
| 1 | 1/2 | 0 |
Perfect negative dependence: X determines Y completely. Cov(X,Y)=−1/4.
Covariance quantifies this: positive when they move together, negative when they move opposite, zero when uncorrelated.
2. Formal Definitions
>Cov(X,Y)=E[(X−μX)(Y−μY)].>Definition (Covariance)
Alternative formula:
>ρXY=σXσYCov(X,Y),−1≤ρXY≤1.>Definition (Correlation Coefficient)
The correlation coefficient is a dimensionless measure of linear dependence.
3. Properties of Covariance
- Cov(X,X)=Var(X)
- Cov(X,Y)=Cov(Y,X) (symmetric)
- Cov(aX,bY)=ab⋅Cov(X,Y)
- Cov(X+Y,Z)=Cov(X,Z)+Cov(Y,Z) (bilinear)
- If X,Y independent → Cov(X,Y)=0 (converse false)
Warning: Zero covariance does not imply independence. Example: X∈{−1,0,1}, Y=X2.
4. Correlation: Interpretation
| ρ | Interpretation |
|---|---|
| +1 | Perfect positive linear relationship ( Y=aX+b , a>0 ) |
| >0 | Positive association (tall→heavy) |
| 0 | No linear association |
| <0 | Negative association (rain→debt) |
| −1 | Perfect negative linear relationship ( Y=aX+b , a<0 ) |
5. Computing Covariance: Example
| Y\X | -1 | 0 | 1 |
|---|---|---|---|
| -1 | 1/15 | 2/15 | 2/15 |
| 0 | 2/15 | 1/15 | 2/15 |
| 1 | 2/15 | 2/15 | 1/15 |
Step 1 — Marginals: fX(−1)=5/15=1/3, fX(0)=5/15=1/3, fX(1)=5/15=1/3. Same for Y.
Step 2 — Means: μX=0, μY=0.
Step 3 — E[XY]:
Non-zero terms: (−1)(−1)(1/15)+(−1)(1)(2/15)+(1)(−1)(2/15)+(1)(1)(1/15) =(1/15)−(2/15)−(2/15)+(1/15)=−2/15.
Step 4 — Covariance: Cov(X,Y)=E[XY]−μXμY=−2/15−0=−2/15.
6. Practice Questions
Q1 (Easy)
X∈{0,1}, Y∈{0,1} with P(X=1)=0.6, P(Y=1)=0.7, P(X=1,Y=1)=0.5. Find Cov(X,Y).
Full SolutionE[X]=0.6, E[Y]=0.7, E[XY]=P(X=1,Y=1)=0.5.Cov(X,Y)=0.5−(0.6)(0.7)=0.5−0.42=0.08 (positive).
Q2 (Medium)
Given fXY below, find ρXY.
| Y\X | 0 | 1 |
|---|---|---|
| 0 | 1/4−x | 1/4+x |
| 1 | 1/4+x | 1/4−x |
Full SolutionμX=μY=0.5. Var(X)=Var(Y)=0.25.E[XY]=0⋅0(1/4−x)+0⋅1(1/4+x)+1⋅0(1/4+x)+1⋅1(1/4−x)=1/4−x.Cov(X,Y)=(1/4−x)−(0.5)(0.5)=−x.ρXY=0.25⋅0.25−x=0.25−x=−4x.For x>0 → negative correlation; x=0 → uncorrelated; x=1/4 → ρ=−1 (perfect negative).
Next topic: Week 3.4: Markov & Chebyshev Inequalities — Markov and Chebyshev inequalities. Join Discord PreviousWeek 3.2: Variance & Standard DeviationNextWeek 3.4: Markov & Chebyshev Inequalities