Expectation for two variables

07 Theory

Theory 1

Expectation for a function on two variables

Discrete case:

E[g(X,Y)]=k,g(k,)PX,Y(k,)(sum over possible values)

Continuous case:

E[g(X,Y)]=++g(x,y)fX,Y(x,y)dxdy

These formulas are not trivial to prove, and we omit the proofs. (Recall the technical nature of the proof we gave for E[g(X)] in the discrete case.)

Expectation sum rule

Suppose X and Y are any two random variables on the same probability model.

Then:

E[X+Y]=E[X]+E[Y]

We already know that expectation is linear in a single variable: E[aX+b]=aE[X]+b.

Therefore this two-variable formula implies:

E[aX+bY+c]=aE[X]+bE[Y]+c

Expectation product rule: independence

Suppose that X and Y are independent.

Then we have:

E[XY]=E[X]E[Y]

Extra - Proof: Expectation sum rule, continuous case

Suppose fX and fY give marginal PDFs for X and Y, and fX,Y gives their joint PDF.

Then:

E[X+Y]++(x+y)fX,Y(x,y)dxdy++xfX,Ydxdy+++yfX,Ydxdy+x(+fX,Ydy)dx++y(+fX,Ydx)dy+xfX(x)dx++yfY(y)dyE[X]+E[Y]

Observe that this calculation relies on the formula for E[g(X,Y)], specifically with g(x,y)=x+y.

Extra - Proof: Expectation product rule

E[XY]++(xy)fX,Y(x,y)dxdy++(xy)fX(x)fY(y)dxdy(independence)+xfX(x)dx+yfY(y)dyE[X]E[Y]
Link to original

08 Illustration

E[X2+Y] from joint PMF chart

Expectation of X squared plus Y from joint PMF chart

Suppose the joint PMF of X and Y is given by this chart:

YX12
10.20.2
00.350.1
10.050.1

Define W=X2+Y. Find the expectation E[W].

Solution

First compute the values of W for each pair (X,Y) in the chart:

YX12
103
014
125

Now take the sum, weighted by probabilities:

0(0.2)+3(0.2)+1(0.35)+4(0.1)+2(0.05)+5(0.1)1.95=E[W] Link to original

Exercise - Understanding expectation for two variables

Understanding expectation for two variables

Suppose you know only that XGeo(p) and YBin(n,q).

Which of the following can you calculate?

E[X+Y],E[XY],E[X2+Y2],E[(X+Y)2]Link to original

E[Y] two ways, and E[XY], from joint density

Expectation of Y two ways and Expectation of XY from joint density

Suppose X and Y are random variables with the following joint density:

fX,Y(x,y)={316xy2x,y[0,2]0 otherwise 

(a) Compute E[Y] using two methods.

(b) Compute E[XY].

Solution

(a)

(1) Method One: via marginal PDF fY(y):

fY(y)=02316xy2dx{38y2y[0,2]0otherwise

Then expectation:

E[Y]=02yfY(y)dy0238y3dy3/2

(2) Method Two: directly, via two-variable formula:

E[Y]=0202y316xy2dydx0234xdx3/2

(b) Directly, via two-variable formula:

E[XY]=0202xy316xy2dydx0234x2dx2Link to original

Covariance and correlation

09 Theory

Theory 1

Write μX=E[X] and μY=E[Y].

Observe that the random variables XμX and YμY are “centered at zero,” meaning that E[XμX]=0=E[YμY].

Covariance

Suppose X and Y are any two random variables on a probability model. The covariance of X and Y measures the typical synchronous deviation of X and Y from their respective means.

Then the defining formula for covariance of X and Y is:

Cov[X,Y]=E[(XμX)(YμY)]

There is also a shorter formula:

Cov[X,Y]=E[XY]E[X]E[Y]

To derive the shorter formula, first expand the product (XμX)(YμY) and then apply linearity.

Notice that covariance is always symmetric:

Cov[X,Y]=Cov[Y,X]

The self covariance equals the variance:

Cov[X,X]=Var[X]

The sign of Cov[X,Y] reveals the correlation type between X and Y:

CorrelationSign
Positively correlatedCov[X,Y]>0
Negatively correlatedCov[X,Y]<0
UncorrelatedCov[X,Y]=0

Correlation coefficient

Suppose X and Y are any two random variables on a probability model.

Their correlation coefficient is a rescaled version of covariance that measures the synchronicity of deviations:

ρ[X,Y]=Cov[X,Y]σXσY=Cov[XσX,YσY]

The rescaling ensures:

1ρX,Y+1

center

Covariance depends on the separate variances of X and Y as well as their relationship.

Correlation coefficient, because we have divided out σXσY, depends only on their relationship.

Link to original

10 Illustration

Covariance from PMF chart

Covariance from PMF chart

Suppose the joint PMF of X and Y is given by this chart:

YX12
10.20.2
00.350.1
10.050.1

Find Cov[X,Y].

Solution

We need E[X] and E[Y] and E[XY].

E[X]=1(0.2+0.35+0.05)+2(0.2+0.1+0.1)1.4 E[Y]=1(0.2+0.2)+0(0.35+0.1)+1(0.05+0.1)0.25 E[XY]=1(0.2)2(0.2)+0+1(0.05)+2(0.1)0.35

Therefore:

Cov[X,Y]=E[XY]E[X]E[Y]0.35(1.4)(0.25)0 Link to original

11 Theory

Theory 2

Covariance bilinearity

Given any three random variables X, Y, and Z, we have:

Cov[X+Y,Z]=Cov[X,Z]+Cov[Y,Z]Cov[Z,X+Y]=Cov[Z,X]+Cov[Z,Y]

Covariance and correlation: shift and scale

Covariance scales with each input, and ignores shifts:

Cov[aX+b,Y]=aCov[X,Y]=Cov[X,aY+b]

Whereas shift or scale in correlation only affects the sign:

ρ[aX+b,Y]=sign(a)ρ[X,Y]=ρ[X,aY+b]

Extra - Proof of covariance bilinearity

Cov[X+Y,Z]E[(X+Y(μX+μY))(ZμZ)]E[(XμX+YμY)(ZμZ)]E[(XμX)(ZμZ)]+E[(YμY)(ZμZ)]Cov[X,Z]+Cov[Y,Z]

Extra - Proof of covariance shift and scale rule

Cov[aX+b,Y]E[(aX+b)Y]E[aX+b]E[Y]E[aXY+bY]aE[X]E[Y]E[b]E[Y]aE[XY]+bE[Y]aE[X]E[Y]bE[Y]a(E[XY]E[X]E[Y])

Independence implies zero covariance

Suppose that X and Y are any two random variables on a probability model.

If X and Y are independent, then:

Cov[X,Y]=0

Proof:

We know both of these:

E[XY]=E[X]E[Y](independence)Cov[X,Y]=E[XY]μXμY(shorter form)

But E[XY]=E[X]E[Y]=μXμY, so those terms cancel and Cov[X,Y]=0.

Sum rule for variance

Suppose that X and Y are any two random variables on a probability space.

Then:

Var[X+Y]=Var[X]+Var[Y]+2Cov[X,Y]

When X and Y are independent:

Var[X+Y]=Var[X]+Var[Y]

Extra - Proof: Sum rule for variance

Var[X+Y]E[(X+Y(μX+μY))2]E[((XμX)+(YμY))2]E[(XμX)2+(YμY)2+2(XμX)(YμY)]Var[X]+Var[Y]+2Cov[X,Y]

Extra - Proof that 1ρ+1

(1) Create standardizations:

X~=XμXσX,Y~=YμYσY

Now X~ and Y~ satisfy:

E[X~]=0=E[Y~]andVar[X~]=1=Var[Y~]

Observe that Var[W]0 for any W. Variance can’t be negative.


(2) Apply the variance sum rule.

Apply to X~ and Y~:

0Var[X~+Y~]=Var[X~]+Var[Y~]+2Cov[X~,Y~]

Simplify:

1+1+2Cov[X~,Y~]01+Cov[X~,Y~]0

Notice effect of standardization:

Cov[X~,Y~]=ρ[X,Y]

Therefore ρ[X,Y]1.


(3) Modify and reapply variance sum rule.

Change to X~Y~:

0Var[X~Y~]=Var[X~]+Var[Y~]+2Cov[X~,Y~]

Simplify:

1+12Cov[X~,Y~]01Cov[X~,Y~]0
Link to original

12 Illustration

Variance of sum of indicators

Variance of sum of indicators

An urn contains 3 red balls and 2 yellow balls.

Suppose 2 balls are drawn without replacement, and X counts the number of red balls drawn.

Find Var[X].

Solution

Let X1 indicate (one or zero) whether the first ball is red, and X2 indicate whether the second ball is red, so X=X1+X2.

Then X1X2 indicates whether both drawn balls are red; so it is Bernoulli with success probability 3524=310. Therefore E[X1X2]=310.

We also have E[X1]=E[X2]=35.

The variance sum rule gives:

Var[X]=Var[X1]+Var[X2]+2Cov[X1,X2]E[X12]E[X1]2+E[X22]E[X2]2+2(E[X1X2]E[X1]E[X2])35(35)2+35(35)2+2(3103535)925Link to original

Exercise - Covariance rules

Covariance rules

Simplify:

Cov[2X+5Y+1,3Y+8W+X+9] Link to original

Exercise - Independent variables are uncorrelated

Dependent but uncorrelated variables

Let X be given with possible values {1,0,+1} and PMF given (uniformly) by PX(k)=1/3 for all three possible k. Let Y=X2.

Show that X and Y are dependent but uncorrelated.

Hint: To speed the calculation, notice that X3=X.

Link to original