# My goal is to calculate $\operatorname{Cov}(X,Y)$, but I'm struggling to calculate $E[XY]$

Regarding the following problem:

A fair coin is tossed 5 times. Let $$X$$ be the number of heads in all $$5$$ tosses, and $$Y$$ be the number of heads in the first $$4$$ tosses. What is $$\operatorname{Cov}(X,Y)$$?

My attempt:

I know that I should calculate the following: $$\operatorname{Cov}(X,Y) = E[XY]-E[X]E[Y]$$

Well, the right flank is pretty easy: $$E[X]=2.5, E[Y]=2$$

But what about $$E[XY]$$?

I searched online and saw that:

$$E[XY]=\sum_{x}\sum_{y}xyP(X=x, Y=y)$$

But any attempt to imply that in the problem only led me for further more confusion.

• Use the fact that $X=Y + Z$ where $Z$ is independent of $Y$ and $\mathbb{P}(Z=1)=\mathbb{P}(Z=0)=1/2$, this is because $X$ and $Y$ can differ only due to the last toss – Hayk Jan 22 at 16:37

Here's a way to do it without messy arithmetic. Let $$T_i$$ be the result of the $$i$$'th toss ($$0$$ if tails, $$1$$ if heads). These are independent, with $$X = T_1 + \ldots + T_5$$ and $$Y = T_1 + \ldots + T_4$$. Then $$\text{Cov}(X,Y) = \text{Cov}(Y+T_5, Y) = \text{Cov}(Y,Y) + \text{Cov}(T_5,Y) = \text{Cov}(Y,Y) = \text{Var}(Y)$$ Now since $$T_1, \ldots, T_4$$ are independent, $$\text{Var}(Y) = \text{Var}(T_1) + \ldots + \text{Var}(T_4) = 4 \text{Var}(T_1)$$ and $$\text{Var}(T_1)$$ is easy to find...

• why does $Cov(T5,Y)=0$ ? thanks! – superuser123 Jan 22 at 17:00
• Because they are independent. – Robert Israel Jan 22 at 17:10

$$X$$ can assume the values $$0,1,2,3,4,5$$ and $$Y$$ can assume the values $$0,1,2,3,4$$. One of the terms in the sum, for example, is $$5\cdot 4\cdot P(X=5,Y=4)=5\cdot 4\cdot \frac{1}{2^{5}}$$

The rest of the terms are computed similarly. Note that you'll want to use $$P(X=x,Y=y)=P(Y=y)\cdot P(X=x|Y=y)$$ A helpful observation: $$P(X=x,Y=y)=0$$ if $$x (since we cannot have more heads in the first $$4$$ tosses than in all $$5$$), so many of the terms in the sum are $$0$$.

• If I sum it up it turns out to be $\frac{70}{32}$ which is incorrect, what did I miss here? – superuser123 Jan 22 at 17:27
• That is also what I'm getting for the sum. What makes you say it's incorrect? – pwerth Jan 22 at 17:30
• $Cov(X,Y)=1$ according to the answers, and it doesn't come up like that, unless I'm missing something – superuser123 Jan 22 at 17:44
• My apologies, the sum is not equal to $\frac{70}{32}$. I believe you assumed each outcome to have the same probability of $\frac{1}{2^{5}}$ which is not correct. This is true for the example I gave in my answer because there is only $1$ outcome of the possible $2^{5}=32$ in which all $5$ flips are heads. But there are multiple outcomes where, say, we have $X=2,Y=1$, since the first "heads" can appear at any of the first $4$ flips. – pwerth Jan 22 at 17:52
• The sum should work out to $\frac{192}{32}=6$, which means the covariance is indeed $6-(2)(2.5)=1$ – pwerth Jan 22 at 17:54