# Expected value of “composite” probability distributions

Let $$X$$ be a uniform random number in $$0..n$$. Its expected value is $$n/2$$.

Next, let $$Y$$ obey a binomial distribution with $$X$$ trials and success probability $$p$$. So now we have a distribution where one of the parameters is itself a random variable. I'm not sure how this is called, but it reminds me of composite functions.

Can I compute the expected value of $$Y$$ simply as $$X\cdot p$$, and subsitute $$n/2$$ for $$X$$, yielding an expected value of $$np/2$$ for $$Y$$? If not, how do we compute the expected value of a distribution that has a parameter that is a random variable itself?

• I suppose you want $X$ to be uniform on $1,\ldots,n$ because a binomial distribution with $0$ trials would just be the degenerate random variable $0$. Or are you okay with that? – Math1000 Nov 16 '19 at 2:28
• By the way, what this is "called" is that $Y$, conditional on $X=n$ has $\mathrm{Bin}(n,p)$ distribution. With a slight abuse of notation, we can write $Y\mid X=n\sim\mathrm{Bin}(n,p)$. – Math1000 Nov 16 '19 at 2:31
• @Math1000 I think 0 trials should be a valid input to the binomial distribution. Of course, in that case the random variable will always be zero, but that's okay. Anyway, it's just an example, and I hope an answer will be generically enough so that I can apply it to arbitrary interval bounds. :) – user1494080 Nov 16 '19 at 2:36
• In that case, $$\mathbb E[Y] = \sum_{k=0}^n \mathbb E[Y\mid X=k]\mathbb P(X=k) = \sum_{k=0}^n kp\cdot\frac1{n+1} = \frac{np}2,$$ as expected. I will write this as an answer as well. – Math1000 Nov 16 '19 at 2:40

By the law of total expectation we compute $$\mathbb E[Y] = \sum_{k=0}^n \mathbb E[Y\mid X=k]\mathbb P(X=k) = \sum_{k=0}^n kp\cdot\frac1{n+1} = \frac{np}2,$$ as expected.
• Thank you, just to be sure I understood the prinicple: Let $W$ be an additional uniform random number in $0..m$ and let $X$ now be uniform in $0..W$. Then the expected value of this chain of three distributions would be $\Sigma_{j=0}^m\Sigma_{k=0}^j E[Y | X = k]P(X=k | W = j)P(W=j) = pm/4$. Is that correct? – user1494080 Nov 16 '19 at 3:35