# What is the variance of a binomial distribution with random number of trials?

According to Wikipedia (https://en.wikipedia.org/wiki/Binomial_distribution), the variance of a binomial distribution of $n$ independent trials, where each trial has an outcome probability of $p$, is given by $np(1-p)$.

But what is the overall variance of the distribution if the number of trials $n$ is itself a binomial distribution having a mean value of $m$ and a variance of $v$?

For background information, I'm trying to build an Excel model of projects flowing through successive phases of drug development, where a binomial distribution of projects starts one phase, and the probability that each project passes into the next phase is given by $p$, so I want to forecast the distribution (mean and variance) of projects passing from one phase to the next.

• Do you know the law of total variance? Apr 19 '17 at 22:28
• Nope, but now that you mention, I'm going to look it up. Thanks for the pointer. Apr 19 '17 at 22:29
• OK, just looked it up, but looks incomprehensible to me. Struggling to understand it, let alone how to apply it. :-( Apr 19 '17 at 22:33
• I'm trying to build an Excel model of projects flowing through successive phases of drug development, where a binomial distribution of projects starts one phase, and the probability that each project passes into the next phase is given by $p$, so I want to forecast the distribution (mean and variance) of projects passing into the next phase. Apr 19 '17 at 23:06
• Excellent information, thanks -- that should be in your question, since it clarifies something about what you're asking. Please edit your question (you could just paste that right at the end and it would do nicely I think). While you're editing, "with sample number variance" in the title is a little ambiguous; perhaps "with random number of trials" or "random n" might work better. Apr 19 '17 at 23:09

Your hierarchical model is underspecified. If $N$ is binomial with variance $v$, this does not uniquely specify $N$.
Instead, suppose we have $X \mid N \sim \operatorname{Binomial}(N,p)$ and $N \sim \operatorname{Binomial}(n,\theta)$. We find by the law of total variance \begin{align*} \operatorname{Var}[X] &= \operatorname{Var}[\operatorname{E}[X \mid N]] + \operatorname{E}[\operatorname{Var}[X \mid N]] \\ &= \operatorname{Var}[Np] + \operatorname{E}[Np(1-p)] \\ &= p^2 \operatorname{Var}[N] + p(1-p)\operatorname{E}[N] \\ &= p^2 n\theta(1-\theta) + p(1-p) n\theta \\ &= np\theta (p(1-\theta) + (1-p)) \\ &= np\theta (1-p\theta). \end{align*} This of course, is the variance of a binomial distribution with parameters $n$ and $p\theta$. Since by the law of total expectation we also have $$\operatorname{E}[X] = \operatorname{E}[\operatorname{E}[X \mid N]] = \operatorname{E}[Np] = np\theta,$$ this suggests (but does not prove) that the marginal distribution of $X$ could be binomial. Can you prove or disprove the claim $$X \overset{?}{\sim} \operatorname{Binomial}(n,p\theta)?$$
• So based on your answer and my edited question (using the variables as I have labeled and defined them), am I correct that the overall variance would be $mp(1-p)+vp^2$? Apr 20 '17 at 0:58