# Find conditional expectation given a discrete random variable whose range is N

Consider the following random variables in $$(\Omega, \mathfrak{F}, P)$$.

1. $$X_1,X_2, X_3,...$$ where $$\forall n \in \mathbb{N}, \mu_n = E(X_n), \sigma_n^2 = Var(X_n) < \infty$$.
2. $$N$$, a discrete RV whose range is $$\mathbb{N}$$. Let $$A_n = ({\omega: N(\omega) = n})$$ and $$p_n = P (N = n) = P(A_n)$$. Also, $$N$$ is independent of each $$X_n$$.
3. $$\mu_N$$ defined as $$\mu_N (\omega) = \mu_{N(w)}, \sigma_N^2 (\omega) = \sigma^2_{N (\omega)}$$, and $$X_N$$ defined as $$X_N (\omega) = X_{N(\omega)} (\omega)$$.

Interpretation: if we choose an index n at random (so $$N=n$$), then $$X_N$$ is the RV $$X_n$$ and $$\mu_N$$ is the mean of $$X_n$$, and $$\sigma_N^2$$ is the variance of $$X_n$$.

Prove that $$E[X_N|N] = E[X_N|\sigma(N)] = \mu_N$$ and $$Var[X_N|N] = Var[X_N|\sigma(N)] = \sigma_N^2.$$ Use these to find formulas for $$E[X_N]$$ and $$Var[X_N]$$ in terms of $$\mu_n, \sigma^2_n$$ and $$p_n$$.

My attempt:

Edit: I already proved the conditional expectation stuff. I just want to see if my formulas for $$E[X_N]$$ and $$Var[X_N]$$ in terms of $$\mu_n, \sigma^2_n$$ and $$p_n$$ are correct:

$$Var[X_N] = E[Var[X_N|N]] + Var[E[X_N|N]]$$

$$=E[\sigma_N^2] + Var[\mu_N]$$

$$=E[\sigma_N^2] + E[\mu_N^2] - E[\mu_N]^2$$

$$=\sum_{n=1}^{\infty} \sigma_n^2 p_n + \sum_{n=1}^{\infty} \mu_n^2 p_n - (\sum_{n=1}^{\infty} \mu_n p_n)^2$$

Explanation of sums and stuff: (For $$E[\mu_N]$$)

$$E[X_N|N]$$ is $$\sigma(N)$$-measurable. Thus, $$\exists$$ Borel-measurable function g such that $$g(N) = E[X_N|N]$$

$$\to E[E[X_N|N]] = E[g(N)]$$

$$\to E[X_N] = E[g(N)]$$

$$\to E[X_N] = \sum_{n=1}^{\infty} g(n) p_n$$

where $$g(n) = E(X_N | N = n) = E[X_n 1_{A_n}]/p_n = E[X_n]p_n/p_n = E(X_n) = \mu_n$$

$$E[X_N] = E[\mu_N] = \sum_{n=1}^{\infty} \mu_n p_n$$

Similarly, I came up with expressions for $$E[X_N^2]$$ and $$Var[X_N]$$.

Are these expressions correct?

Since $$X_N=\sum_{n\geqslant 1} X_n\mathbf{1}_{N=n}$$ holds pointwise, we have $${\rm E}[X_N]=\sum_{n\geqslant 1}\mu_np_n$$ agreeing with your expression. Similarly, $${\rm E}[X_N^2]=\sum_{n\geqslant 1}{\rm E}[X_n^2]p_n=\sum_{n\geqslant 1}(\sigma_n^2+\mu_n^2)p_n$$ and hence $${\rm Var}(X_N)=\sum_{n\geqslant 1} (\sigma_n^2+\mu_n^2)p_n-\left(\sum_{n\geqslant 1} \mu_np_n\right)^2$$ also agreeing with your expression.