# Computing $\mathbb{E}(S_n)$ and $\mathbb{V}(S_n)$ for Bernoulli data with a uniform probability parameter?

Take $$U \sim \text{U}(0,1)$$ as an underlying probability and generate $$X_1,X_2,...,X_n \sim \text{Bern}(U)$$ independent Bernoulli trials with this probability. The number of successes in the sample is:

$$S_n = \sum_{i=1}^n X_i.$$

How do I go about computing $$\mathbb{E}(S_n)$$ and $$\mathbb{V}(S_n)$$?

• Welcome to CV. Since you’re new here, you may want to take our tour, which has information for new users. Since this looks like homework (apologies if it's not), please add the [self-study] tag and read its wiki. Then tell us what you understand thus far, what you've tried & where you're stuck. We'll provide hints to help you get unstuck. Please make these changes as just posting your homework & hoping someone will do it for you is grounds for closing. If this is self-study rather than homework, let us know, and... it's still a good idea to show us what you've tried. Commented Mar 26, 2020 at 15:24
• This has nothing to do with statistics. Please check the law of total expectation as a possible hint. Commented Mar 26, 2020 at 15:35
• @Xian is absolutely correct but it's also called the "iterated law of expectations" and the "tower property" in case you want to google for those. I'm only mentioning these terms because I was not familiar with the term "total expectations" so maybe the other terms are more popular ? I don't know but it's good to know all the terms if you're going to go googling. Commented Mar 26, 2020 at 18:34

$$\mathbb{P}(S_n=s|U=u) = \text{Bin}(s|n, u).$$
$$\mathbb{E}(S_n|U=u) = nu \quad \quad \quad \mathbb{V}(S_n|U=u) = nu(1-u).$$
To obtain the marginal mean and variance (i.e., not conditioning on $$U$$) you will need to obtain the moments of the underlying conditioning random variable $$u$$, and then you can apply the law of iterated expectation and the law of iterated variance. Give this a go and see what answers you get.