Solved – How to calculate the binomial probability when expected frequency is a random variable

binomial distributiondistributionsprobability

I am trying to write a simple likelihood function to calculate the binomial probability of $X$ successes from $N$ trials. The problem is that the expected proportion of successes ($p_X$) is itself a binomially-distributed variable with $Y$ successes and $M$ trials.

That is, there a simple way to calculate $\text{E}(X)$ for $X\sim \text{Bin}(N, Y/M)$ when $Y\sim \text{Bin}(M, p)$?

Is it just the product of the two probabilities?

Best Answer

This can be done using the Law of Total Expectation.

$$\text{E} (X) = \text{E}_Y [ \text{E}_{X | Y} ( X | Y)]$$

Now $\text{E}_{X|Y}(X|Y)] = N\cdot p_x = N\cdot Y/M$, so

\begin{eqnarray} \text{E} (X) &=& \text{E}_Y [ N\cdot Y/M]\\ &=& \frac{N}{M}\cdot\text{E}_Y [Y]\\ &=& \frac{N}{M}\cdot (Mp)\\ &=& Np \end{eqnarray}