Processing math: 100%

15 Multivariate Expectation

15.1 Objectives

  1. Given a joint pmf/pdf, obtain means and variances of random variables and functions of random variables.

  2. Define the terms covariance and correlation, and given a joint pmf/pdf, obtain the covariance and correlation between two random variables.

  3. Given a joint pmf/pdf, determine whether random variables are independent of one another.

  4. Find conditional expectations.

15.2 Homework

15.2.1 Problem 1

Let X and Y be continuous random variables with joint pdf: fX,Y(x,y)=x+y

where 0x1 and 0y1.

  1. Find E(X) and E(Y). We will use the marginal pdfs found in the Application 14 solution.

E(X)=10x(x+12)dx=x33+x24|10=13+14=712=0.583 Or numerically:

f <- function(x) { x[1]*(x[1] + x[2]) } # "x" is vector
adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(1, 1))
## $integral
## [1] 0.5833333
## 
## $error
## [1] 1.110223e-16
## 
## $functionEvaluations
## [1] 17
## 
## $returnCode
## [1] 0

E(Y)=10y(y+12)dy=0.583

  1. Find Var(X) and Var(Y).

Var(X)=E(X2)E(X)2 E(X2)=10x2(x+12)dx=x44+x36|10=14+16=512=0.417 As a check:

f <- function(x) { x[1]^2*(x[1] + x[2]) } # "x" is vector
round(adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(1, 1))$integral,3)
## [1] 0.417

So, Var(X)=0.4170.5832=0.076.

Similarly, Var(Y)=0.076.

  1. Find Cov(X,Y) and ρ. Are X and Y independent? Cov(X,Y)=E(XY)E(X)E(Y) E(XY)=1010xy(x+y)dydx=10x2y22+xy33|10dx=10x22+x3dx =x36+x26|10=13=0.333

As a check:

f <- function(x) { x[1]*x[2]*(x[1] + x[2]) } # "x" is vector
round(adaptIntegrate(f, lowerLimit = c(0, 0), upperLimit = c(1, 1))$integral,3)
## [1] 0.333

So, Cov(X,Y)=13(712)2=0.007

ρ=Cov(X,Y)Var(X)Var(Y)=0.0070.076×0.076=0.0909

As a check:

-0.007/sqrt(.076^2)
## [1] -0.09210526

Using exact values:

(1/3-(7/12)^2)/sqrt((5/12-(7/12)^2)^2)
## [1] -0.09090909

With a non-zero covariance, X and Y are not independent.

  1. Find Var(3X+2Y). Var(3X+2Y)=Var(3X)+Var(2Y)+2Cov(3X,2Y)= 9Var(X)+4Var(Y)+12Cov(X,Y)= 90.076+40.076+120.007=0.910

15.2.2 Problem 2

Optional - not difficult but does have small Calc III idea. Let X and Y be continuous random variables with joint pmf: fX,Y(x,y)=1

where 0x1 and 0y2x.

  1. Find E(X) and E(Y). E(X)=10x2xdx=2x33|10=0.667

E(Y)=20y(1y2)dy=y22y36|20=286=0.667

  1. Find Var(X) and Var(Y). E(X2)=10x22xdx=x42|10=0.5

So, Var(X)=0.5(23)2=118=0.056

E(Y2)=20y2(1y2)dy=y33y48|20=832=0.667

So, Var(Y)=23(23)2=29=0.222

  1. Find Cov(X,Y) and ρ. Are X and Y independent?

E(XY)=102x0xydydx=10xy22|2x0dx=102x3dx=x42|10=12

So, Cov(X,Y)=122323=118=0.056

ρ=Cov(X,Y)Var(X)Var(Y)=11811829=0.5

X and Y appear to be positively correlated (thus not independent).

  1. Find Var(X2+2Y). Var(X2+2Y)=14Var(X)+4Var(Y)+2Cov(X,Y)=172+89+19=1.014

15.2.3 Problem 3

Suppose X and Y are independent random variables. Show that E(XY)=E(X)E(Y).

If X and Y are independent, then Cov(X,Y)=0. So, Cov(X,Y)=E(XY)E(X)E(Y)=0

Thus, E(XY)=E(X)E(Y)

15.2.4 Problem 4

You are playing a game with a friend. Each of you roll a fair sided die and record the result.

  1. Write the joint probability mass function.

Let X be the number on your die and Y be the number on your friend’s die.

X12345611361361361361361362136136136136136136Y3136136136136136136413613613613613613651361361361361361366136136136136136136

  1. Find the expected value of the product of your score and your friend’s score.

To find E[XY], we determine all 36 values of the product of X and Y and multiply by the associated probabilities. Since the probabilities are all equal, we will take the 136 out of the summation. Now

E[XY]=136(1+2+3+4+5+6+2+4+ 6+8+10+12+3+6+9+12+15+18+4+8+12+16+20+24+ 5+10+15+20+25+30+6+12+18+24+30+36) =12.25

  1. Verify the previous part using simulation.
set.seed(1012)
(do(100000)*(sample(1:6,size=2,replace=TRUE))) %>%
  mutate(prod=V1*V2) %>%
  summarize(Expec=mean(prod))
##      Expec
## 1 12.25016
  1. Using simulation, find the expected value of the maximum number on the two roles.
(do(100000)*max(sample(1:6,size=2,replace=TRUE))) %>%
    summarize(Expec=mean(max))
##    Expec
## 1 4.4737

15.2.5 Problem 5

A miner is trapped in a mine containing three doors. The first door leads to a tunnel that takes him to safety after two hours of travel. The second door leads to a tunnel that returns him to the mine after three hours of travel. The third door leads to a tunnel that returns him to his mine after five hours. Assuming that the miner is at all times equally likely to choose any one of the doors, yes a bad assumption but it makes for a nice problem, what is the expected length of time until the miner reaches safety?

Simulating this is a little more challenging because we need a conditional but we try it first before going to the mathematical solution.

Let’s write a function that takes a vector and returns the sum of the values up to the first time the number 2 appears, we are using the time values as our sample space. Anytime you are repeating something more than 5 times, it might make sense to write a function.

miner_time <- function(x){
  index <- which(x==2)[1]
  total<-cumsum(x)
  return(total[index])
}
set.seed(113)
(do(10000)*miner_time(sample(c(2,3,5),size=20,replace=TRUE))) %>% 
  summarise(Exp=mean(miner_time))
##       Exp
## 1 10.0092

Now let’s find it mathematically.

Let X be the time it takes and Y the door. Then we have

E[X]=E[E[X|Y]] =13E[X|Y=1]+13E[X|Y=2]+13E[X|Y=3] Now if door 2 is selected E[X|Y=2]=E[X]+3 since the miner will travel for 3 hours and then be back at the starting point.

Likewise if door 3 is select E[X|Y=2]=E[X]+5 So E[x]=132+13(E[X]+3)+13(E[X]+5)

E[x]23E[X]=23+33+53 13E[X]=103

E[X]=10

15.2.6 Problem 6

ADVANCED: Let X1,X2,...,Xn be independent, identically distributed random variables. (This is often abbreviated as “iid”). Each Xi has mean μ and variance σ2 (i.e., for all i, E(Xi)=μ and Var(Xi)=σ2).

Let S=X1+X2+...+Xn=ni=1Xi. And let ˉX=ni=1Xin.

Find E(S), Var(S), E(ˉX) and Var(ˉX). E(S)=E(X1+X2+...+Xn)=E(X1)+E(X2)+...+E(Xn)=μ+μ+...+μ=nμ

Since the Xis are all independent: Var(S)=Var(X1+X2+...+Xn)=Var(X1)+Var(X2)+...+Var(Xn)=nσ2

E(ˉX)=1nE(X1+X2+...+Xn)=1nnμ=μ Var(ˉX)=1n2Var(X1+X2+...+Xn)=1n2nσ2=σ2n