# How to calculate the expected value of k heads in this case?

I'm having some trouble on how to tackle the following problem

$$X_1$$ is a random variable with probability density $$f(x)$$ in the range $$[0,1]$$. A value of $$X_1$$ is picked, call its value $$p$$. A coin is played $$n$$ times with a probability $$p$$ to come up heads in each time. Calculate the expected value of the number of $$k$$ heads in the $$n$$ plays in the following cases:

1. Each coin toss is independent and the $$p$$ value is the same for all of them. Find an expression for $$E [k]$$ in the case of a general $$f(x)$$

2. Find $$E[k]$$ if $$f(x)$$ is uniform over $$[0,1]$$

3. Find $$E[k]$$ if $$f(x)$$ is uniform over $$[0,1]$$ and a new $$p$$ value is picked before each coin flip.

I'm not sure I'm interpreting this correctly and honestly I think it's a little bit confusing.

If $$p$$ is fixed, the PMF would be the binomial distribution. In the case of a general $$f(x)$$, I assume I've to first derive a posterior distribution for $$X_1$$, where $$f(x)$$ is the prior. I'd proceed by finding the likelilhood based on the information that the coin was flipped $$n$$ times with a probability $$p$$ to come up heads. Then I could find the distribution for the next $$m$$ plays and calculate the expected value for this case. Here starts the trouble for me - it's asking for the expected value of the same $$n$$ plays I'm using to construct the likelihood. Because of that I'm not sure my approach is correct.

Also, I would appreciate some insight in the case where $$X_1$$ is picked before each coin flip.

Thanks.

• So in (1), from the binomial distribution, the expectation is $E[k]=E[np]=nE[X_1]$. Similarly for (2), though you can actually find $E[X_1]$ Jun 4, 2020 at 14:13
• Is this a question from a course or textbook? If so, please add the [self-study] tag & read its wiki. Jun 4, 2020 at 14:16
• There is nothing Bayesian about this. Hint: 2 & 3 are examples of compound-distributions, which are somewhat confusingly sometimes called "mixtures", so you may have seen them under that name. Does that help? Jun 4, 2020 at 14:18
• @StephanKolassa This definitely helps. Just to make things clear, I can derive an expression for the distribution of k by marginalizing over the binomial distribution and f(p), is that correct? But what happens when I have to deal with multiple parameters as in 3 (which I presume is the case because there's no guarantee p is the same each time I flip a coin) ? Is the mathematical generalization just a multiple integral? Jun 4, 2020 at 22:44

I think this is like a conditional probability and marginal probability problem. First, for RV $$X_1$$, we have pdf $$f(x)$$ and range [0,1]. Then given '$$X_1$$' we have $$k$$ obeying a binomial distribution with pmd $$g(k/p)=\binom nk p^k(1-p)^{n-k}$$.
Now $$E(k)=E(E(k|X_1))=nE(X_1)$$
$$E(X_1)=\int_{0}^{1}xf(x)dx$$
$$E(k)=n\int_{0}^{1}xf(x)dx$$
When $$f(x)$$ is uniform. $$E(k)=n\int_{0}^{1}x\frac{1}{1}dx=n(\frac{1}{2}-0)=\frac{n}{2}$$