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?
 A: 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:


*

*$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.

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

*$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.
A: 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)$.
A: Have you tried calculating the marginal distribution? In general, for a discrete Binomial random variable the following is true:
\begin{align*}
p(y) &= \sum_x p(y,x)\\
&=\sum_x p(y|x)p(x)
\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.
