Salta al contenuto
Note per Studenti Covariance and Correlation Report

Covariance and Correlation

In questa pagina 4

Motivation to the study of random vectors.

Variance of the sum of two random variables

Let Z=X+YZ=X+Y and compute

var(Z)=E((Z−E(Z))2)=E((X+Y−E(X)−E(Y))2)=E((X−E(X)+Y−E(Y))2)\mathrm{var}(Z)=E\big((Z-E(Z))^2\big)=E\big((X+Y-E(X)-E(Y))^2\big)=E\big((X-E(X)+Y-E(Y))^2\big)

=E((X−E(X))2)+E((Y−E(Y))2)+2E((X−E(X))(Y−E(Y)))=var(X)+var(Y)+2 cov(X,Y),=E\big((X-E(X))^2\big)+E\big((Y-E(Y))^2\big)+2E\big((X-E(X))(Y-E(Y))\big)=\mathrm{var}(X)+\mathrm{var}(Y)+2\,\mathrm{cov}(X,Y),

where the following new definition was introduced.

Definition (covariance of XX and YY). cov(X,Y)≜E((X−E(X))(Y−E(Y))).\mathrm{cov}(X,Y)\triangleq E\big((X-E(X))(Y-E(Y))\big).

Properties of the covariance

  1. cov(X,Y)=cov(Y,X)\mathrm{cov}(X,Y)=\mathrm{cov}(Y,X).
  2. cov(X,X)=var(X)\mathrm{cov}(X,X)=\mathrm{var}(X).
  3. cov(X,Y)=E(XY)−E(X)E(Y)\mathrm{cov}(X,Y)=E(XY)-E(X)E(Y) (compare with var(X)=E(X2)−[E(X)]2\mathrm{var}(X)=E(X^2)-[E(X)]^2).
  4. cov(aX+b, cY+d)=ac cov(X,Y)\mathrm{cov}(aX+b,\,cY+d)=ac\,\mathrm{cov}(X,Y).

The proof of properties 1-3 is trivial. For property 4 a direct computation gives

cov(aX+b,cY+d)=E[(aX+b)(cY+d)]−E(aX+b)E(cY+d)\mathrm{cov}(aX+b,cY+d)=E[(aX+b)(cY+d)]-E(aX+b)E(cY+d) =ac E(XY)+ad E(X)+bc E(Y)+bd−ac E(X)E(Y)−ad E(X)−bc E(Y)−bd=ac\,E(XY)+ad\,E(X)+bc\,E(Y)+bd-ac\,E(X)E(Y)-ad\,E(X)-bc\,E(Y)-bd =ac[E(XY)−E(X)E(Y)]=ac cov(X,Y).□=ac\big[E(XY)-E(X)E(Y)\big]=ac\,\mathrm{cov}(X,Y).\qquad\square

Remarks

  1. cov(X,Y)\mathrm{cov}(X,Y) can be ≷0\gtrless0 depending on X,YX,Y. For Y=−XY=-X: cov(X,−X)=−var(X)≤0\mathrm{cov}(X,-X)=-\mathrm{var}(X)\le0; for Y=XY=X: cov(X,X)=var(X)≥0\mathrm{cov}(X,X)=\mathrm{var}(X)\ge0.
  2. The special case cov(X,Y)=0\mathrm{cov}(X,Y)=0 is very important and will be studied later (see Independent Random VariablesDiscrete random variables X and Y are independent when the joint density factorizes as p_XY = p_X p_Y for all pairs; independence is preserved by functions f(X), g(Y), implies E(XY) = E(X)E(Y) and var(X + Y) = var(X) + var(Y), but uncorrelated does not imply independent.Independent Random Variables →). For the time being:

Definition (uncorrelated). The random variables X,YX,Y are called uncorrelated if cov(X,Y)=0\mathrm{cov}(X,Y)=0, or equivalently E(XY)=E(X)E(Y)E(XY)=E(X)E(Y).

Reduction of the problem to E(XY)E(XY)

Computing var(X+Y)=var(X)+var(Y)+2cov(X,Y)\mathrm{var}(X+Y)=\mathrm{var}(X)+\mathrm{var}(Y)+2\mathrm{cov}(X,Y) is reduced to computing cov(X,Y)\mathrm{cov}(X,Y), since var(X)\mathrm{var}(X) and var(Y)\mathrm{var}(Y) are known. As cov(X,Y)=E(XY)−E(X)E(Y)\mathrm{cov}(X,Y)=E(XY)-E(X)E(Y) and E(X),E(Y)E(X),E(Y) are known, everything reduces to E(XY)E(XY).

Definition (correlation). E(XY)E(XY) is called the correlation of XX and YY.

Why E(XY)E(XY) cannot be computed from the marginals

Consider discrete X,YX,Y with available data: the alphabet X\mathcal{X} and density pX(xk)p_X(x_k) of XX; the alphabet Y\mathcal{Y} and density pY(yℓ)p_Y(y_\ell) of YY. It is impossible to compute E(XY)E(XY): let Z=XYZ=XY; its values are zm=xkyℓz_m=x_ky_\ell with xk∈Xx_k\in\mathcal{X}, yℓ∈Yy_\ell\in\mathcal{Y}, but pZ(zm)p_Z(z_m) cannot be computed from pX(xk)p_X(x_k) and pY(yℓ)p_Y(y_\ell). At a fundamental level

pZ(zm)=P([Z=zm])=P([X=xk]∩[Y=yℓ]),p_Z(z_m)=P([Z=z_m])=P([X=x_k]\cap[Y=y_\ell]),

while the data are pX(xk)=P([X=xk])p_X(x_k)=P([X=x_k]) and pY(yℓ)=P([Y=yℓ])p_Y(y_\ell)=P([Y=y_\ell]). This is equivalent to trying to find P(E∩F)P(E\cap F) from the knowledge of P(E)P(E) and P(F)P(F), an impossible task in general.

Example. Let X,Y∼b(p)X,Y\sim b(p) (Bernoulli). The random variable Z=XYZ=XY is again Bernoulli: its alphabet is {0,1}\{0,1\} with Z=1Z=1 iff X=1X=1 and Y=1Y=1, and Z=0Z=0 in all other cases. Therefore

E(XY)=0⋅P(XY=0)+1⋅P(XY=1)=P([X=1]∩[Y=1]).E(XY)=0\cdot P(XY=0)+1\cdot P(XY=1)=P([X=1]\cap[Y=1]).

But the available data are only P(X=1)=P(Y=1)=pP(X=1)=P(Y=1)=p, and it is impossible to compute P([X=1]∩[Y=1])P([X=1]\cap[Y=1]). To complete the computation one needs extra information on the joint behaviour of XX and YY. This is what Discrete Random VectorsA discrete random vector (X,Y) is described by its joint discrete density p_XY(x_i,y_j) = P(X = x_i, Y = y_j), whose marginals are obtained by summing over the other variable and which gives expectations of any function g(X,Y), including E(XY), covariance and the density of X + Y.Discrete Random Vectors → provide; a worked numerical case of var(X+Y)\mathrm{var}(X+Y) with X,Y∼b(0.4)X,Y\sim b(0.4) is given there.

Versione ripasso

Variance of a sum. var(X+Y)=var(X)+var(Y)+2 cov(X,Y)\mathrm{var}(X+Y)=\mathrm{var}(X)+\mathrm{var}(Y)+2\,\mathrm{cov}(X,Y).

Covariance. cov(X,Y)=E((X−E(X))(Y−E(Y)))=E(XY)−E(X)E(Y)\mathrm{cov}(X,Y)=E\big((X-E(X))(Y-E(Y))\big)=E(XY)-E(X)E(Y).

Properties. symmetric; cov(X,X)=var(X)\mathrm{cov}(X,X)=\mathrm{var}(X); cov(aX+b,cY+d)=ac cov(X,Y)\mathrm{cov}(aX+b,cY+d)=ac\,\mathrm{cov}(X,Y) (proof: expand, the terms with b,db,d cancel). Sign can be anything: Y=−X⇒−var(X)Y=-X\Rightarrow-\mathrm{var}(X), Y=X⇒var(X)Y=X\Rightarrow\mathrm{var}(X).

Uncorrelated: cov(X,Y)=0  ⟺  E(XY)=E(X)E(Y)\mathrm{cov}(X,Y)=0\iff E(XY)=E(X)E(Y). Correlation: E(XY)E(XY).

Key point. E(XY)E(XY) (hence cov\mathrm{cov} and var(X+Y)\mathrm{var}(X+Y)) is not determined by the marginals: for X,Y∼b(p)X,Y\sim b(p), E(XY)=P([X=1]∩[Y=1])E(XY)=P([X=1]\cap[Y=1]) needs the joint law. P(E∩F)P(E\cap F) cannot be found from P(E)P(E), P(F)P(F).

Typical mistakes. Writing var(X+Y)=var(X)+var(Y)\mathrm{var}(X+Y)=\mathrm{var}(X)+\mathrm{var}(Y) without checking cov=0\mathrm{cov}=0; forgetting the factor 22; thinking cov(aX+b,cY+d)\mathrm{cov}(aX+b,cY+d) depends on b,db,d.

Teoria collegata