$\DeclareMathOperator{\Bin}{Bin}$ I have two binomial random variables, $X \sim \Bin (n, p)$, and $Y \sim \Bin (X, q)$.

From this I can see that the conditional distribution of $Y|X$ is binomial, i.e., $Y | X=x \sim \Bin (x, q)$. As I understand, here, Y is a conditional binomial where n = another binomial.

I also see from this previous discussion: https://stats.stackexchange.com/questions/112516/binomial-random-variable-conditional-on-another-one that we can prove that the unconditional distribution of $Y$ is also binomial, i.e., $Y \sim \Bin (n, pq)$.

Now, I am trying to evaluate $E(X|Y)$ and I have to get it as a function of $Y$, or in terms of the distribution of a random variable that's known to us here. I tried the following:

$$E(X|Y=y) = \sum_{x= 0}^n x P(X=x | Y=y)$$

To calculate $P(X=x | Y=y)$, I need $P(X=x, Y=y)$ and $P(Y=y)$.

To get $P(Y=y)$, I am using the unconditional distribution of $Y\sim \Bin(n, pq)$.

This gives me $P(Y=y) = \ ^nC_y \cdot (pq)^y \cdot (1-pq)^{n-y}$. (I wonder whether I can do this?)

Then, I calculate $P(X=x, Y=y) = P(Y=y | X=x) \cdot P(X=x)$

For this, I use $Y|X \sim \Bin(x, q)$, and $X \sim \Bin(n, p)$.

That is, $P(Y=y | X=x) = \ ^xC_y \cdot q^y \cdot (1-q)^{x-y}$, and $P(X=x) = \ ^nC_x \cdot p^x \cdot (1-p)^{n-x}$

When I worked it out, I am getting an expression for $P(X=x, Y=y)$, in terms of $n$, $x$, $y$, $p$, $q$, and $pq$, which doesn't seem to reduce to anything that's known (like, say, the pmf of a binomial).

Where am I going wrong here? I am ultimately trying to find $E(X|Y)$. I have been asked to use results regarding the conditional distribution, and also that the $E(X|Y)$ will be a function of $Y$. Thanks a ton for any help on figuring out what I am missing here...


I also see that $E(E(X|Y)) = E(X) = np$, which means that $E(X|Y)$ is itself a binomial random variable. Is this relevant in any way for finding $E(X|Y)$?

  • $\begingroup$ It is highly recommended to format your math equations with MathJax. Please check this and/or other references for formatting your question. $\endgroup$ Sep 17, 2023 at 1:16
  • $\begingroup$ Thank you! Yes, I have been reading up on how to obtain Latex-type font for the math parts in my question. I am working on editing it to reflect the formatting... $\endgroup$ Sep 17, 2023 at 1:20

2 Answers 2


If we take for granted that $$Y \sim \operatorname{Binomial}(n,pq),$$ then $$\Pr[X = x \mid Y = y] = \frac{\Pr[Y = y \mid X = x]\Pr[X = x]}{\Pr[Y = y]}, \tag{1}$$ by Bayes' theorem. And we have all of the relevant PMFs, so:

$$\begin{align} \Pr[X = x \mid Y = y] &= \frac{\binom{x}{y} q^y (1-q)^{x-y} \binom{n}{x} p^x (1-p)^{n-x}}{\binom{n}{y} (pq)^y (1-pq)^{n-y}}. \tag{2} \end{align}$$

Let's work out the binomial coefficients first. We have

$$\frac{\binom{x}{y} \binom{n}{x}}{\binom{n}{y}} = \frac{x!}{y!(x-y)!} \frac{n!}{x!(n-x)!} \frac{y!(n-y)!}{n!} = \frac{(n-y)!}{(x-y)!(n-x)!} = \binom{n-y}{x-y}. \tag{3}$$ This makes sense because we must remember that $0 \le Y \le X \le n$. So this suggests letting $m = n-y$, $w = x-y$, or equivalently, $$y = n-m, \quad x = w+y = n-m+w, \tag{4}$$ and writing the rest of the factors in $(2)$ as follows:

$$\begin{align} \frac{q^y(1-q)^{x-y} p^x (1-p)^{n-x}}{(pq)^y (1-pq)^{n-y}} &= \frac{q^y}{q^y} p^{x-y} (1-q)^{x-y} \frac{(1-p)^{n-x}}{(1-pq)^{n-y}} \\ &= \frac{(p(1-q))^{x-y} (1-p)^{m-w}}{(1-pq)^m} \\ &= \frac{(p(1-q))^w (1-p)^m}{(1-p)^w (1-pq)^m} \\ &= \left(\frac{p(1-q)}{1-p}\right)^w\left(\frac{1-p}{1-pq}\right)^m. \tag{5} \end{align}$$ We aren't quite done: If $m$ plays the role of the upper binomial coefficient argument, and $w$ plays the role of the lower, then our exponents in a corresponding binomial PMF should be $w$ and $m-w$, rather than $w$ and $m$. So we write $(5)$ as

$$\begin{align} \left(\frac{p(1-q)}{1-p}\right)^w\left(\frac{1-p}{1-pq}\right)^m &= \left(\left. \frac{p(1-q)}{1-p} \right/ \frac{1-p}{1-pq} \right)^w \left(\frac{1-p}{1-pq}\right)^{m-w} \\ &= \left(\frac{p(1-q)}{1-pq}\right)^w \left(\frac{1-p}{1-pq}\right)^{m-w} \\ &= s^w t^{m-w}, \end{align} \tag{6}$$ where $$s = \frac{p(1-q)}{1-pq}, \quad t = \frac{1-p}{1-pq}. \tag{7}$$ So putting this all together, $$\Pr[X = x \mid Y = y] = \binom{m}{w} s^w t^{m-w}. \tag{8}$$ It looks like it could be a binomial PMF, but is it? We need to check that $s + t = 1$. And it is: $$s + t = \frac{p(1-q)}{1-pq} + \frac{1-p}{1-pq} = \frac{p - pq + 1-p}{1-pq} = \frac{1-pq}{1-pq} = 1. \tag{9}$$ So we can write $(8)$ as $$\begin{align}\Pr[X = x \mid Y = y] &= \binom{m}{w} s^w (1-s)^{m-w}, \quad w \in \{0, 1, \ldots, m\} \\ &= \binom{n-y}{x-y} s^{x-y} (1-s)^{n-x}, \quad x \in \{y, y+1, \ldots, n\}. \tag{10} \end{align}$$ But $X \mid Y = y$ is not binomial, strictly speaking. It is a location-shifted binomial because the support is on $\{y, y+1, \ldots, n\}$, as $(10)$ above illustrates. This property is inherited from the earlier restriction $0 \le Y \le X \le n$, which in turn is due to the fact that $Y$ conditioned on $X$ cannot exceed $X$. Another way to conceptualize this is to see that once we have observed $Y = y$, this tells us that $X$ cannot be less than $y$, since then it would be impossible to have observed $Y = y$.

So we must write instead something like

$$(X - y) \mid Y = y \sim \operatorname{Binomial}\left( n-y, \frac{p(1-q)}{1-pq} \right). \tag{11}$$

This does not stop us from computing the conditional expectation, however. It is in fact immediate:

$$\operatorname{E}[X \mid Y = y] = \operatorname{E}[X - y \mid Y = y] + y = (n-y)\frac{p(1-q)}{1-pq} + y. \tag{12}$$ And we can now also write this in terms of the random variable $Y$ rather than a realization $y$:

$$\operatorname{E}[X \mid Y] = (n-Y)\frac{p(1-q)}{1-pq} + Y = \frac{1-p}{1-pq} Y + \frac{np(1-q)}{1-pq}. \tag{13}$$

  • $\begingroup$ These steps have been so helpful in understanding. I get it now - conditional on Y=y, the maximum value that X-y can take is n-y, since X has to be at least y when Y=y. The minimum value of X-y is 0, given Y=y (so that the minimum value that X can take is y, when Y=y). This makes the conditional distribution of X-y binomial. The intuitive explanation makes it easier to visualize/imagine why the formulas work. Thank you so much for sharing your knowledge. $\endgroup$ Sep 18, 2023 at 2:25

The joint distribution is $$P(X=x, Y=y) = P(Y=y \mid X=x) P(X=x) = \binom{x}{y} q^y(1-q)^{x-y} \binom{n}{x} p^x (1-p)^{n-x}$$ for $0 \le y \le x \le n$. You also know that $Y \sim \text{Binom}(n, pq)$.

After some cumbersome accounting, \begin{align} P(X = x \mid Y=y) &= \frac{P(X=x, Y=y)}{P(Y=y)} \\ &= \frac{\binom{x}{y} q^y (1-q)^{x-y} \binom{n}{x} p^x (1-p)^{n-x}}{\binom{n}{y} (pq)^y (1-pq)^{n-y}} \\ &= \binom{n-y}{x-y} \left(\frac{p(1-q)}{1-pq}\right)^{x-y} \left(\frac{1-p}{1-pq}\right)^{n-x} \end{align} If we make the change of variables $x=y+z$ and let $r := \frac{p(1-q)}{1-pq}$, we can write this as $$P(X=y+z \mid Y=y) = \binom{n-y}{z} r^z (1-r)^{(n-y)-z}.$$ Thus conditional on $Y=y$, we have that $X-y \sim \text{Binom}\left(n-y, \frac{p(1-q)}{1-pq}\right)$.

The linked answer provides a simpler approach to arrive at this result. There, $X=\sum_{i=1}^n X_i$ where $X_i \sim \text{Ber}(p)$, and $Y = \sum_{i=1}^n X_i Z_i$ where $Z_i \sim \text{Ber}(q)$. Then $X-Y$ is the number of pairs $(X_i, Z_i)$ such that $X_i=1$ and $Z_i=0$. Conditioning on $Y=y$, there are $n-y$ pairs such that $X_i Z_i \ne 1$, and the conditional probability of $X_i=1$ and $Z_i=0$ given that $X_iZ_i \ne 1$ is $$P(X_i=1, Z_i=0 \mid X_i Z_i \ne 1) = \frac{p(1-q)}{1-pq)}.$$

  • $\begingroup$ Thank you for this explanation and for the linked answer. I'll also work out the alternative methods to learn another way of dealing with this. $\endgroup$ Sep 18, 2023 at 2:28

You must log in to answer this question.