Covariance and the Correlation Coefficient

Definition of the Covariance

Mathematical Definition of the Covariance

Covariance

Let XX and YY be two random variables. If both E(X)E(X) and E(Y)E(Y) exist, then: Cov(X,Y)=E[(X−E(X))(Y−E(Y))]Cov(X,Y) = E[(X - E(X))(Y - E(Y))]

is called the covariance of XX and YY.

Computation Formula for the Covariance

Discrete random variables: Cov(X,Y)=∑i,j(xi−E(X))(yj−E(Y))P(X=xi,Y=yj)Cov(X,Y) = \sum_{i,j} (x_i - E(X))(y_j - E(Y))P(X = x_i, Y = y_j)

Continuous random variables: Cov(X,Y)=∫−∞+∞∫−∞+∞(x−E(X))(y−E(Y))f(x,y)dxdyCov(X,Y) = \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} (x - E(X))(y - E(Y))f(x,y) dx dy

Simplified Computation Formula for the Covariance

Simplified Computation Formula for the Covariance

Cov(X,Y)=E(XY)−E(X)E(Y)Cov(X,Y) = E(XY) - E(X)E(Y)

Proof: Cov(X,Y)=E[(X−E(X))(Y−E(Y))]=E(XY−XE(Y)−YE(X)+E(X)E(Y))Cov(X,Y) = E[(X - E(X))(Y - E(Y))] = E(XY - XE(Y) - YE(X) + E(X)E(Y)) =E(XY)−E(X)E(Y)−E(Y)E(X)+E(X)E(Y)=E(XY)−E(X)E(Y)= E(XY) - E(X)E(Y) - E(Y)E(X) + E(X)E(Y) = E(XY) - E(X)E(Y)

Intuitive Understanding of the Covariance

Understanding: the covariance reflects the degree of linear correlation between two random variables. A positive value indicates a positive correlation, a negative value indicates a negative correlation, and a zero value indicates no correlation.

Examples of the Covariance

Example 1: suppose the joint distribution law of XX and YY is:

X\YX \backslash Y01
00.30.2
10.20.3

Find Cov(X,Y)Cov(X,Y).

Solution:

  1. E(X)=0×0.5+1×0.5=0.5E(X) = 0 \times 0.5 + 1 \times 0.5 = 0.5
  2. E(Y)=0×0.5+1×0.5=0.5E(Y) = 0 \times 0.5 + 1 \times 0.5 = 0.5
  3. E(XY)=0×0×0.3+0×1×0.2+1×0×0.2+1×1×0.3=0.3E(XY) = 0 \times 0 \times 0.3 + 0 \times 1 \times 0.2 + 1 \times 0 \times 0.2 + 1 \times 1 \times 0.3 = 0.3
  4. Cov(X,Y)=E(XY)−E(X)E(Y)=0.3−0.5×0.5=0.05Cov(X,Y) = E(XY) - E(X)E(Y) = 0.3 - 0.5 \times 0.5 = 0.05

Properties of the Covariance

Symmetry

Property 1: Cov(X,Y)=Cov(Y,X)Cov(X,Y) = Cov(Y,X)

Proof: Cov(X,Y)=E[(X−E(X))(Y−E(Y))]=E[(Y−E(Y))(X−E(X))]=Cov(Y,X)Cov(X,Y) = E[(X - E(X))(Y - E(Y))] = E[(Y - E(Y))(X - E(X))] = Cov(Y,X)

Linearity

Property 2: Cov(aX+b,cY+d)=ac⋅Cov(X,Y)Cov(aX + b, cY + d) = ac \cdot Cov(X,Y), where a,b,c,da, b, c, d are constants.

Proof: Cov(aX+b,cY+d)=E[(aX+b−E(aX+b))(cY+d−E(cY+d))]Cov(aX + b, cY + d) = E[(aX + b - E(aX + b))(cY + d - E(cY + d))] =E[(aX−aE(X))(cY−cE(Y))]=ac⋅E[(X−E(X))(Y−E(Y))]=ac⋅Cov(X,Y)= E[(aX - aE(X))(cY - cE(Y))] = ac \cdot E[(X - E(X))(Y - E(Y))] = ac \cdot Cov(X,Y)

Additivity

Property 3: Cov(X1+X2,Y)=Cov(X1,Y)+Cov(X2,Y)Cov(X_1 + X_2, Y) = Cov(X_1, Y) + Cov(X_2, Y)

Proof: Cov(X1+X2,Y)=E[(X1+X2−E(X1+X2))(Y−E(Y))]Cov(X_1 + X_2, Y) = E[(X_1 + X_2 - E(X_1 + X_2))(Y - E(Y))] =E[(X1−E(X1)+X2−E(X2))(Y−E(Y))]= E[(X_1 - E(X_1) + X_2 - E(X_2))(Y - E(Y))] =E[(X1−E(X1))(Y−E(Y))]+E[(X2−E(X2))(Y−E(Y))]=Cov(X1,Y)+Cov(X2,Y)= E[(X_1 - E(X_1))(Y - E(Y))] + E[(X_2 - E(X_2))(Y - E(Y))] = Cov(X_1, Y) + Cov(X_2, Y)

Relation with the Variance

Property 4: Cov(X,X)=D(X)Cov(X, X) = D(X)

Proof: Cov(X,X)=E[(X−E(X))2]=D(X)Cov(X, X) = E[(X - E(X))^2] = D(X)

Covariance of Independent Random Variables

Property 5: if XX and YY are independent, then Cov(X,Y)=0Cov(X, Y) = 0

Proof: if XX and YY are independent, then E(XY)=E(X)E(Y)E(XY) = E(X)E(Y), so Cov(X,Y)=E(XY)−E(X)E(Y)=0Cov(X, Y) = E(XY) - E(X)E(Y) = 0

Note: the converse does not hold, that is, Cov(X,Y)=0Cov(X, Y) = 0 does not necessarily mean that XX and YY are independent.

Definition of the Correlation Coefficient

Mathematical Definition of the Correlation Coefficient

Correlation Coefficient

Let XX and YY be two random variables with D(X)>0D(X) > 0 and D(Y)>0D(Y) > 0. Then: ρXY=Cov(X,Y)D(X)D(Y)=Cov(X,Y)σXσY\rho_{XY} = \frac{Cov(X,Y)}{\sqrt{D(X)D(Y)}} = \frac{Cov(X,Y)}{\sigma_X \sigma_Y}

is called the correlation coefficient of XX and YY, where σX=D(X)\sigma_X = \sqrt{D(X)} and σY=D(Y)\sigma_Y = \sqrt{D(Y)}.

Properties of the Correlation Coefficient

Property 1: −1≤ρXY≤1-1 \leq \rho_{XY} \leq 1

Proof: use the Cauchy-Schwarz inequality: ∣E[(X−E(X))(Y−E(Y))]∣≤E[(X−E(X))2]E[(Y−E(Y))2]|E[(X - E(X))(Y - E(Y))]| \leq \sqrt{E[(X - E(X))^2]E[(Y - E(Y))^2]} Hence ∣Cov(X,Y)∣≤σXσY|Cov(X,Y)| \leq \sigma_X \sigma_Y, that is, ∣ρXY∣≤1|\rho_{XY}| \leq 1.

Property 2: ρXY=1\rho_{XY} = 1 if and only if Y=aX+bY = aX + b, where a>0a > 0

Property 3: ρXY=−1\rho_{XY} = -1 if and only if Y=aX+bY = aX + b, where a<0a < 0

Property 4: ρXY=0\rho_{XY} = 0 if and only if Cov(X,Y)=0Cov(X,Y) = 0

Intuitive Understanding of the Correlation Coefficient

Understanding:

  • ρXY=1\rho_{XY} = 1: perfect positive correlation
  • ρXY=−1\rho_{XY} = -1: perfect negative correlation
  • ρXY=0\rho_{XY} = 0: no correlation
  • 0<ρXY<10 < \rho_{XY} < 1: positive correlation
  • −1<ρXY<0-1 < \rho_{XY} < 0: negative correlation

Examples of the Correlation Coefficient

Example 2: continuing Example 1, find ρXY\rho_{XY}.

Solution:

  1. D(X)=E(X2)−[E(X)]2=0.5−0.25=0.25D(X) = E(X^2) - [E(X)]^2 = 0.5 - 0.25 = 0.25
  2. D(Y)=E(Y2)−[E(Y)]2=0.5−0.25=0.25D(Y) = E(Y^2) - [E(Y)]^2 = 0.5 - 0.25 = 0.25
  3. σX=σY=0.25=0.5\sigma_X = \sigma_Y = \sqrt{0.25} = 0.5
  4. ρXY=Cov(X,Y)σXσY=0.050.5×0.5=0.2\rho_{XY} = \frac{Cov(X,Y)}{\sigma_X \sigma_Y} = \frac{0.05}{0.5 \times 0.5} = 0.2

Covariance Matrix

Covariance Matrix of a Two-Dimensional Random Variable

Covariance Matrix

Let (X,Y)(X, Y) be a two-dimensional random variable. Its covariance matrix is:

Σ=(D(X)Cov(X,Y)Cov(Y,X)D(Y))=(σX2σXYσYXσY2)\Sigma = \begin{pmatrix} D(X) & Cov(X,Y) \\ Cov(Y,X) & D(Y) \end{pmatrix} = \begin{pmatrix} \sigma_X^2 & \sigma_{XY} \\ \sigma_{YX} & \sigma_Y^2 \end{pmatrix}

Properties of the Covariance Matrix

Property 1: the covariance matrix is a symmetric matrix

Property 2: the covariance matrix is a positive semidefinite matrix

Property 3: if XX and YY are independent, then the covariance matrix is a diagonal matrix

Covariance of Multidimensional Random Variables

Covariance Matrix of a Multidimensional Random Variable

Covariance Matrix (Multidimensional Case)

Let X=(X1,X2,…,Xn)TX = (X_1, X_2, \dots, X_n)^T be an nn-dimensional random variable. Its covariance matrix is:

Σ=(D(X1)Cov(X1,X2)…Cov(X1,Xn)Cov(X2,X1)D(X2)…Cov(X2,Xn)⋮⋮⋱⋮Cov(Xn,X1)Cov(Xn,X2)…D(Xn))\Sigma = \begin{pmatrix} D(X_1) & Cov(X_1,X_2) & \dots & Cov(X_1,X_n) \\ Cov(X_2,X_1) & D(X_2) & \dots & Cov(X_2,X_n) \\ \vdots & \vdots & \ddots & \vdots \\ Cov(X_n,X_1) & Cov(X_n,X_2) & \dots & D(X_n) \end{pmatrix}

Properties for Multidimensional Random Variables

Property 1: the covariance matrix is a symmetric matrix

Property 2: the covariance matrix is a positive semidefinite matrix

Property 3: if X1,X2,…,XnX_1, X_2, \dots, X_n are pairwise independent, then the covariance matrix is a diagonal matrix

Applications of the Covariance and the Correlation Coefficient

Applications in Statistics

Application 1: linear regression The correlation coefficient is an important indicator for measuring the strength of a linear relationship.

Application 2: principal component analysis The covariance matrix is the foundation of principal component analysis.

Application 3: multivariate statistical analysis The covariance matrix is the core of multivariate statistical analysis.

Applications in Finance

Application 4: portfolio theory The covariance matrix is used to compute the risk of a portfolio.

Application 5: risk management The correlation coefficient is used to evaluate the effect of risk diversification among different assets.

Exercises

Exercise 1

Given E(X)=1,E(Y)=2,Cov(X,Y)=3,σX=2,σY=1E(X)=1, E(Y)=2, Cov(X,Y)=3, \sigma_X=2, \sigma_Y=1, find ρXY\rho_{XY}.

correlation coefficientdefinition and computationstandardization

Approach: Use the definition of the correlation coefficient.

Steps:

  1. ρXY=Cov(X,Y)σXσY\rho_{XY} = \frac{Cov(X,Y)}{\sigma_X \sigma_Y}
  2. =32×1=1.5= \frac{3}{2 \times 1} = 1.5

Answer: 1.51.5

Exercise 2

Given that the joint distribution law of the random variables XX and YY is:

X\YX \backslash Y01
00.40.1
10.10.4

Find Cov(X,Y)Cov(X,Y).

covariancecomputation formulajoint distribution law

Approach: Use the simplified computation formula for the covariance.

Steps:

  1. E(X)=0×0.5+1×0.5=0.5E(X) = 0 \times 0.5 + 1 \times 0.5 = 0.5
  2. E(Y)=0×0.5+1×0.5=0.5E(Y) = 0 \times 0.5 + 1 \times 0.5 = 0.5
  3. E(XY)=0×0×0.4+0×1×0.1+1×0×0.1+1×1×0.4=0.4E(XY) = 0 \times 0 \times 0.4 + 0 \times 1 \times 0.1 + 1 \times 0 \times 0.1 + 1 \times 1 \times 0.4 = 0.4
  4. Cov(X,Y)=E(XY)−E(X)E(Y)=0.4−0.5×0.5=0.15Cov(X,Y) = E(XY) - E(X)E(Y) = 0.4 - 0.5 \times 0.5 = 0.15

Answer: 0.150.15

Exercise 3

Given that XX and YY are independent, D(X)=4D(X) = 4, and D(Y)=9D(Y) = 9, find D(X+Y)D(X + Y).

varianceindependence and additivityvariance computation

Approach: Use the additivity of the variance for independent random variables.

Steps:

  1. If XX and YY are independent, then D(X+Y)=D(X)+D(Y)D(X + Y) = D(X) + D(Y)
  2. =4+9=13= 4 + 9 = 13
  3. Independence is exactly the premise of the additivity of the variance; here XX and YY are independent, so the two variances can be added directly.

Answer: D(X+Y)=13D(X + Y) = 13.

Exercise 4

Given that the correlation coefficient of the random variables XX and YY is 0.80.8, D(X)=4D(X) = 4, and D(Y)=9D(Y) = 9, find Cov(X,Y)Cov(X,Y).

correlation coefficientdefinition and computationstandardization

Approach: Use the definition of the correlation coefficient.

Steps:

  1. ρXY=Cov(X,Y)D(X)D(Y)\rho_{XY} = \frac{Cov(X,Y)}{\sqrt{D(X)D(Y)}}
  2. 0.8=Cov(X,Y)4×9=Cov(X,Y)60.8 = \frac{Cov(X,Y)}{\sqrt{4 \times 9}} = \frac{Cov(X,Y)}{6}
  3. Cov(X,Y)=0.8×6=4.8Cov(X,Y) = 0.8 \times 6 = 4.8

Answer: 4.84.8

Exercise 5

Prove that if XX and YY are independent, then ρXY=0\rho_{XY} = 0.

correlation coefficientindependenceproof

Approach: Use the fact that the covariance of independent random variables is zero.

Steps:

  1. If XX and YY are independent, then Cov(X,Y)=0Cov(X,Y) = 0
  2. Hence ρXY=Cov(X,Y)D(X)D(Y)=0D(X)D(Y)=0\rho_{XY} = \frac{Cov(X,Y)}{\sqrt{D(X)D(Y)}} = \frac{0}{\sqrt{D(X)D(Y)}} = 0

Answer: the proof is complete


Summary

Symbols Used in This Article

Greek LetterPronunciationDescription
ρ\rhoRho (rho)denotes the correlation coefficient
σ\sigmaSigma (sigma)denotes the standard deviation

Found an issue with this content?

Tell us what could be improved.