# Sum of a subset of i.i.d. Bernoulli r.v.s conditional on their total sum

Suppose we have i.i.d. $$\xi_1,\dots,\xi_n\sim Bernoulli(p)$$ and define $$\tau=\sum_{i=1}^n\xi_i,\eta=\sum_{j=1}^{\tau}\xi_j$$.

Find $$\mathbb{E}\eta$$.

Unlike in some of the similar problems solved here, this one involves dependent r.v.s.

I start by computing the expected value of one of the i.i.d. $$\xi_i$$ conditional on a fixed value of $$\tau$$ denoted as $$k$$: \begin{align*} &\mathbb{E}(\xi_i|\tau=k)=1\cdot\mathbb{P}(\xi_i=1|\tau=k)+0=\frac{\binom{n-1}{k-1}}{\binom{n}{k}}=\frac{k}{n} \end{align*}

I don't understand how to go from here to $$\mathbb{E}(\xi_i|\tau)$$. Obviously, if $$\tau=k, only $$k$$ of the variables $$\xi_i$$ are equal to 1. I've tried to write:

$$\mathbb{E}(\xi_i|\tau)\sum_{i=1}^n\frac{i}{n}=\frac{1+n}{2}\cdot n\cdot p$$ but I don't think it's right.

Is there something I am doing wrong? How to compute the expected value in question properly?

• @Surb how come? I'm quite sure that if $\tau$ is 0, $\xi_i$ is also zero for all $i$. Commented Aug 7 at 11:21
• @Surb how do I compute $\mathbb{E}\eta$ then? $\tau$ obviously makes a difference here. I understand, it's equal to $\mathbb{E}\mathbb{E}(\eta|\tau)$ but I don't have ideas how to compute $\mathbb{E}(\eta|\tau)$ Commented Aug 7 at 11:44

Detailing your initial calculations: \begin{align} \mathbb P(\xi_i=1|\tau=k) &= \frac{\mathbb P(\tau=k|\xi_i=1)\mathbb P(\xi_i=1)}{\mathbb P(\tau=k)} \\ &= \frac{\binom{n-1}{k-1}p^{k-1}(1-p)^{n-k}p}{\binom nkp^k(1-p)^{n-k}} \\ &= \frac kn \end{align} You are almost there. You forgot to reweigh by the probability of $$(\tau=k)$$. In detail: \begin{align} \mathbb E(\eta) &= \mathbb E(\mathbb E(\eta|\tau)) \\ &= \sum_{k=0}^n \mathbb E(\eta|\tau=k)\mathbb P(\tau=k)\\ &= \sum_{k=0}^n \left(\sum_{i=1}^k\mathbb E(\xi_i|\tau=k)\right)\mathbb P(\tau=k)\\ &= \sum_{k=0}^n k\mathbb E(\xi_1|\tau)\binom nkp^k(1-p)^{n-k} \\ &= \sum_{k=0}^n k\binom {n-1}{k-1}p^k(1-p)^{n-k} \\ &= \sum_{k=0}^{n-1} (k+1)\binom {n-1}kp^{k+1}(1-p)^{n-1-k} \\ &= p(p(n-1)+1) \end{align} where I use the fact that the expected value of $$X\sim Binom(n-1,p)$$ is $$\mathbb E(x) = (n-1)p$$. For $$n\to\infty$$, this simplifies to: $$\mathbb E(\eta) \sim p^2n$$
$$\left(\xi_1,\dots,\xi_n\right)'\mid \tau\sim\text{Multivariate Hypergeometic}\left(n, \mathbf{1}_n, \tau\right)$$ with $$\mathbb{E}(\xi_i \mid \tau) = \frac{\tau}{n}$$, and $$\mathbb{E}(\eta)=\mathbb{E}\left[\mathbb{E}\left(\left.\sum_{i=1}^\tau \xi_i \right\vert \tau\right) \right]=\mathbb{E}\left(\tau \cdot \frac{\tau}{n}\right) = \frac1n \left[\mathbb{V}(\tau)+\mathbb{E}^2(\tau)\right]$$ where $$\tau\sim\text{Binomial}(n,p)$$. Plugging in binomial mean and variance gives $$\mathbb{E}(\eta)=p(1-p)+np^2.$$