# Two random coins from a hat, let $X$ be the number of heads after flipping the chosen coin $n$ times. Find the variance of $X$.

One of two identical-looking coins is picked from a hat randomly, where one coin has probability $p_1$ of Heads and the other has probability $p_2$ of Heads. Let $X$ be the number of Heads after flipping the chosen coin n times. Find the variance of $X$.

I not exactly sure how to represent this mathematically because there are variances from both coins. Can I just sum up the variances? That is,

$$Var(X) = \frac{1}{2} Var(X \mid C_1) + \frac{1}{2} Var(X \mid C_2)$$

Here $C_j$ is the event that coin $j$ is chosen where $j \in {1,2}$. And $X \mid C_j \sim Binom(n,p_j)$. This results in:

$$Var(X) = \frac{1}{2}(np_1(1-p_1)+np_2(1-p_2))$$

This is not the same as the solution, the solution is:

$$Var(X) = \frac{1}{2}(np_1(1-p_1)+np_2(1-p_2)) + \frac{1}{4}n^2(p_1-p_2)^2$$

Can anyone please explain why my method did not work? Seems like it's missing a $\frac{1}{4}n^2(p_1-p_2)^2$ term.

• Lets take this to the extreme where the one coin has both sides tails, and one coin has both sides heads (i.e. $p_1=0, p_2=1$). The variance of each coin individually is zero (as it will always be the same result), however the variance of the overall procedure is certainly not zero (since different outcomes are possible). Commented Jun 3, 2016 at 17:44
• Your approach would work by calculating things like $\mathbb Ef(X)$, but fails by variance. This because term $\mathbb EX$ in the expression $\mathbb E(X-\mathbb EX)^2$ is also affected. Commented Jun 4, 2016 at 7:15

We can write $X=UY_1+VY_2$ where $Y_i$ has binomial distribution with parameters $n,p_i$ and where $U$ has Bernoulli($\frac12$)-distribution and $U+V=1$.

This with independence of $U,Y_1,Y_2$.

Then to be worked out is:

$$\text{Var}X=\text{Var}\left(UY_{1}+VY_{2}\right)=\text{Var}\left(UY_{1}\right)+2\text{Cov}\left(UY_{1},VY_{2}\right)+\text{Var}\left(VY_{2}\right)$$

• Hmm, what do you do with $Var(UY_1)$ since both $U$ and $Y_1$ are random variables? Is it just $Var(UY_1)=E((UY_1)^2)-(E(UY_1))^2=E(U^2)E(Y_1^2)-(E(U))^2(E(Y_1))^2$?
– jlcv
Commented Jun 3, 2016 at 19:30
• @ZoomBee, I have give you the solution from this point on. Goodluck Commented Jun 4, 2016 at 4:27
• @ZoomBee Yes. Also notice that $U^2=U$. Commented Jun 4, 2016 at 6:58

You may also try this:

Let $\displaystyle C \sim \text{Bernoulli}\left(\frac {1} {2}\right)$ such that $X|C = 0 \sim \text{Binomial}(n, p_1)$ and $X|C = 1 \sim \text{Binomial}(n, p_2)$

\begin{align} Var[X] & = E[Var[X|C]] + Var[E[X|C]] \\ & = E[(1-C)np_1(1-p_1) + Cnp_2(1 - p_2)] + Var[(1-C)np_1 + Cnp_2] \\ & = \frac {1} {2} np_1(1-p_1) + \frac {1} {2}np_2(1 - p_2) + Var[n(p_2 - p_1)C]\\ & = \frac {1} {2} np_1(1-p_1) + \frac {1} {2}np_2(1 - p_2) + \frac {1} {4} n^2(p_2 - p_1)^2\\ \end{align}

Essentially just a more compact way to present the above solutions.

• I was one voted it up but the use Eve's law if taught is the best way to solve the problem. Very compact indeed (+1) Commented Jun 4, 2016 at 13:36

When you add the last step, you get

Variance$= \frac{1}{2}\left[np_1(1-p_1) + np_2(1-p_2)\right] + \frac{1}{4}n^2(p_1-p_2)^2$

• Shortcut:$\mathbb{E}Y_{1}^{2}=\text{Var}Y_{1}+\left(\mathbb{E}Y_{1}\right)^{2}=np\left(1-p\right)+\left(np\right)^{2}=n\left(n-1\right)p^{2}+np$ Commented Jun 4, 2016 at 7:08
• Please note @drhab 's comment. It will save you some time. Thanks Commented Jun 4, 2016 at 10:08