Quiz 2

Week 3.3: Covariance & Correlation

601 words
3 min read
Python Week 1: the first filter for runtime behavior
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\XY \backslash X01
01/41/4
11/41/4
Independent: Cov(X,Y)=0\operatorname{Cov}(X,Y) = 0.
Y\XY \backslash X01
001/2
11/20
Perfect negative dependence: XX determines YY completely. Cov(X,Y)=1/4\operatorname{Cov}(X,Y) = -1/4. Covariance quantifies this: positive when they move together, negative when they move opposite, zero when uncorrelated.

2. Formal Definitions

Definition (Covariance)
>Cov(X,Y)=E[(XμX)(YμY)].>> \operatorname{Cov}(X,Y) = \mathbb{E}\left[(X - \mu_X)(Y - \mu_Y)\right]. >
Alternative formula:
Cov(X,Y)=E[XY]E[X]E[Y].\operatorname{Cov}(X,Y) = \mathbb{E}[XY] - \mathbb{E}[X]\mathbb{E}[Y].
Definition (Correlation Coefficient)
>ρXY=Cov(X,Y)σXσY,1ρXY1.>> \rho_{XY} = \frac{\operatorname{Cov}(X,Y)}{\sigma_X \sigma_Y}, \quad -1 \leq \rho_{XY} \leq 1. >
The correlation coefficient is a dimensionless measure of linear dependence.

3. Properties of Covariance

  1. Cov(X,X)=Var(X)\operatorname{Cov}(X,X) = \operatorname{Var}(X)
  2. Cov(X,Y)=Cov(Y,X)\operatorname{Cov}(X,Y) = \operatorname{Cov}(Y,X) (symmetric)
  3. Cov(aX,bY)=abCov(X,Y)\operatorname{Cov}(aX, bY) = ab \cdot \operatorname{Cov}(X,Y)
  4. Cov(X+Y,Z)=Cov(X,Z)+Cov(Y,Z)\operatorname{Cov}(X+Y, Z) = \operatorname{Cov}(X,Z) + \operatorname{Cov}(Y,Z) (bilinear)
  5. If X,YX,Y independent → Cov(X,Y)=0\operatorname{Cov}(X,Y) = 0 (converse false)
Warning: Zero covariance does not imply independence. Example: X{1,0,1}X \in \{-1,0,1\}, Y=X2Y = X^2.

4. Correlation: Interpretation

ρ\rhoInterpretation
+1+1Perfect positive linear relationship ( Y=aX+bY = aX + b , a>0a>0 )
>0>0Positive association (tall→heavy)
00No linear association
<0<0Negative association (rain→debt)
1-1Perfect negative linear relationship ( Y=aX+bY = aX + b , a<0a<0 )

5. Computing Covariance: Example

Y\XY \backslash X-101
-11/152/152/15
02/151/152/15
12/152/151/15
Step 1 — Marginals: fX(1)=5/15=1/3f_X(-1) = 5/15 = 1/3, fX(0)=5/15=1/3f_X(0) = 5/15 = 1/3, fX(1)=5/15=1/3f_X(1) = 5/15 = 1/3. Same for YY. Step 2 — Means: μX=0\mu_X = 0, μY=0\mu_Y = 0. Step 3 — E[XY]\mathbb{E}[XY]:
E[XY]=x,yxyfXY(x,y).\mathbb{E}[XY] = \sum_{x,y} xy \cdot f_{XY}(x,y).
Non-zero terms: (1)(1)(1/15)+(1)(1)(2/15)+(1)(1)(2/15)+(1)(1)(1/15)(-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= (1/15) - (2/15) - (2/15) + (1/15) = -2/15. Step 4 — Covariance: Cov(X,Y)=E[XY]μXμY=2/150=2/15\operatorname{Cov}(X,Y) = \mathbb{E}[XY] - \mu_X\mu_Y = -2/15 - 0 = -2/15.

6. Practice Questions

Q1 (Easy)

X{0,1}X \in \{0,1\}, Y{0,1}Y \in \{0,1\} with P(X=1)=0.6\mathbb{P}(X=1)=0.6, P(Y=1)=0.7\mathbb{P}(Y=1)=0.7, P(X=1,Y=1)=0.5\mathbb{P}(X=1,Y=1)=0.5. Find Cov(X,Y)\operatorname{Cov}(X,Y).
Full Solution
E[X]=0.6\mathbb{E}[X] = 0.6, E[Y]=0.7\mathbb{E}[Y] = 0.7, E[XY]=P(X=1,Y=1)=0.5\mathbb{E}[XY] = \mathbb{P}(X=1,Y=1) = 0.5.
Cov(X,Y)=0.5(0.6)(0.7)=0.50.42=0.08\operatorname{Cov}(X,Y) = 0.5 - (0.6)(0.7) = 0.5 - 0.42 = 0.08 (positive).

Q2 (Medium)

Given fXYf_{XY} below, find ρXY\rho_{XY}.
Y\XY \backslash X01
01/4x1/4-x1/4+x1/4+x
11/4+x1/4+x1/4x1/4-x
Full Solution
μX=μY=0.5\mu_X = \mu_Y = 0.5. Var(X)=Var(Y)=0.25\operatorname{Var}(X) = \operatorname{Var}(Y) = 0.25.
E[XY]=00(1/4x)+01(1/4+x)+10(1/4+x)+11(1/4x)=1/4x\mathbb{E}[XY] = 0\cdot0(1/4-x) + 0\cdot1(1/4+x) + 1\cdot0(1/4+x) + 1\cdot1(1/4-x) = 1/4 - x.
Cov(X,Y)=(1/4x)(0.5)(0.5)=x\operatorname{Cov}(X,Y) = (1/4 - x) - (0.5)(0.5) = -x.
ρXY=x0.250.25=x0.25=4x\rho_{XY} = \frac{-x}{\sqrt{0.25 \cdot 0.25}} = \frac{-x}{0.25} = -4x.
For x>0x > 0 → negative correlation; x=0x = 0 → uncorrelated; x=1/4x = 1/4ρ=1\rho = -1 (perfect negative).

Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.