Binomial random variable conditional on another one

On the Wikipedia page for the Binomial distribution, the following property is mentioned (under the related distribution section): (paraphrased)

If $X\sim \text{Bin}(n,p)$ and $Y|X \sim \text{Bin}(X,q)$, then $Y \sim \text{Bin}(n,pq)$

I interpret this the following way. The probability mass function for $X$ is: $$P(X=x) = \binom{n}{x}p^x(1-p)^{n-x}$$ The conditional mass function for $Y$ given $X=x$ is: $$P(Y=y|X=x) = \binom{x}{y}q^{y} (1-q)^{x-y}$$ The mass function of $Y$ is: $$P(Y=y) = \binom{n}{y} (pq)^y (1-pq)^{n-y}$$

There is no citation for this particular property. I have tried to prove it, but to no avail. I wrote the following R code to get a sense of the veracity of the claim.

# Observations of X & Y to be generated
obs <- 10000

n <- 10
p <- 0.6
q <- 0.4

X <- rbinom(obs, n, p)
Y <- X

for( i in 1:obs)
{
Y[i] <- rbinom(1, X[i], q)
}

# Simulated pmf of Y
hist(Y, breaks=obs)

# Theoretical/claimed pmf
Y_theoretical <- rbinom(obs, n, p*q)
hist(Y_theoretical, breaks=obs)


The two histograms generated are shown below: (The simulated pmf) (Claimed pmf)

Both seem identical for the choice of $p$ and $q$.

Can a proof of this claim be provided?

-

Let $X = \sum_{i=1}^{n} X_i$, with $X_i \overset{iid}{\sim} Bin(1, p)$, and $Z = \sum_{i=1}^{n} Z_i$, with $Z_i \overset{iid}{\sim} Bin(1, q)$. If all the $X_i$ and $Z_i$ are mutually independent, then $Z_i | X_i \overset{iid}{\sim} Bin(1, q)$.

Now to construct $Y$ we want to throw out all the $(X_i, Z_i)$ pairs where $X_i=0$ and then count the number of times $Z_i=1$ in the remaining pairs. That makes $Y | X \sim Bin(x, q)$. We can also write $Y = \sum_{i=1}^{n} Y_i$ with $Y_i = X_i Z_i$. We know $X_i Z_i=1$ if $X_i=1$ and $Z_i=1$, otherwise it is 0. Thus $Y_i \overset{iid}{\sim} Bin(1, pq)$, and $Y \sim Bin(n, pq)$.

-
Why is $Y_i=X_i Z_i$? –  Comp_Warrior Aug 19 '14 at 20:45
Does the edit make it clearer? To get $Y$ we want to take all the times $X_i=1$ and then among those count how many times $Z_i=1$ as well. –  P Schnell Aug 19 '14 at 20:47
Yes, it does now. A very elegant solution! –  Comp_Warrior Aug 19 '14 at 20:49

Looking at the same thing in two different but equivalent ways offers insight.

A Binomial$(n,p)$ variable is the sum of $n$ independent Bernoulli$(p)$ variables. A Bernoulli variable works exactly like drawing one ticket from a box in which all tickets have either a $0$ or $1$ written on them; the proportion of the latter is $p$.

To say that $X=x$ means that $n$ such tickets were drawn from such an "$X$ box" (with replacement each time) and $x$ of them had a $1$ on it. To say that $Y$ has a Binomial$(X,q)$ distribution amounts to performing a second follow-on experiment in which $x$ draws (with replacement) are made from a separate box, the "$Y$ box," in which the proportion of tickets with $1$s is $q$. The value of $Y$ is the count of the $1$s that are drawn.

An alternative way to carry out the same procedure is not to wait until all $n$ tickets are drawn from the $X$ box. Instead, after drawing each ticket, immediately read its value. If it says $X=0$, do nothing more. If it says $X=1$, though, immediately draw a ticket from the $Y$ box and read its value.

This alternative procedure can be described by drawing a single ticket from a new box. Up to two numbers are written on each ticket, called "$X$" and "$Y$", to record a single sequence of up to two draws. According to the foregoing description, which has three outcomes, there must be three kinds of corresponding tickets:

1. $X=0$. These tickets model drawing a value of $0$ from the $X$ box. Their proportion within the new box, in order to emulate the properties of the first step, must equal $1-p$. Don't bother to write any value for $Y$, because $Y$ will not be observed when such a ticket is drawn.

2. $X=1, Y=0$. These tickets model drawing a $1$ from the $X$ box and then a $0$ from the $Y$ box.

3. $X=1, Y=1$. These tickets model drawing a $1$ from the $X$ box and then a $1$ from the $Y$ box.

The total proportion of tickets of types (2) and (3) must equal the proportion of $1$s in an $X$ box, namely $p$. Since $Y$ is drawn independently of $X$, the fraction of the tickets with $X=1$ for which $Y=1$ must be $q$. The fraction of the tickets with $X=1$ for which $Y=0$ similarly must be $1-q$.

To summarize, the three tickets and their proportions in the new box must be

• $X=0$, proportion $p$.

• $X=1, Y=0$, proportion $p(1-q)$.

• $X=1, Y=1$, proportion $pq$.

What kind of variable is $Y$? According to our new (but equivalent) description, it is obtained by drawing $n$ tickets from the new box (with replacement) and counting the number of times a value of $1$ for $Y$ is observed. The only way this can happen is when the third type of ticket is drawn. These occupy a fraction $pq$ of all the tickets. This exhibits $Y$ as the sum of $n$ independent Bernoulli$(pq)$ variables, whence $Y$ has a Binomial$(n, pq)$ distribution.

-

Have you tried calculating the marginal distribution? In general, for a discrete random variable the following is true:

\begin{align*} p(y) &= \sum_x p(y,x) dx\\ &=\sum_x p(y|x)p(x)dx \end{align*}

so all you need to do is show the following:

\begin{align*} p(y) &= \sum_{x=0}^{\infty} \binom{x}{y}q^y(1-q)^{x-y}\binom{n}{x}p^x(1-p)^{n-x}\\ &=\,\,\,\vdots\\ &=\binom{n}{y} (pq)^y (1-pq)^{n-y} \end{align*}

Is this a trivial problem, I don't think so.

-
I am not sure, but the sum should be $\sum_{x=y}^n$ –  niandra82 Aug 19 '14 at 20:40
Shouldn't we be summing over the plausible values of x? Think of the continuous case when you want to integrate out x from f(x,y). We integrate with respect to the support of x. And in this case the support of x does not start at y (although I suppose it should be bounded at n). –  Dan Aug 19 '14 at 20:43
if $x<y$ then what does mean $P(Y|X)$? maybe you have to assume that it is zero –  niandra82 Aug 19 '14 at 20:45
$x<y$ can't happen since $y$ is dependent upon $x$. Right? We are choosing $y$ "successes" out of $x$ trials. So the relationship should really be $y\leq x$ –  Dan Aug 19 '14 at 20:46
I was taking essentially the same approach but the summation seems hard to get through. –  Comp_Warrior Aug 19 '14 at 20:50