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.


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)$$