I am trying to self-learning probabilities using the excellent Grinstead & Snell "Introduction to Probability" (that is also open source).
I am stuck on Example 4.23, that involves a Bernoulli trials where the probability $x$ of $i$ successes is assumed arising from a Beta distribution.
The book firstly defines $m(i|x) = b(n,x,i)$ as the binomial distribution with probability $x$ for success given the value of $x$.
It then explains that, given x is chosen at random from [0,1] with a beta density $B(\alpha,\beta,x)$, the density function for the outcome of the pair $(x,i)$ is
$$f(x,i) = m(i|x) * B(\alpha,\beta,x)$$
My question is: why the two functions are multiplied ? The two events (rising $x$ and $i$) are not surely independent.. In particular why $x$ is not just substituted with its expected value, that on Wikipedia I read being $\frac{\alpha}{\alpha+\beta}$i.e. $$m(i|x) = b(n,x,i) = b(n,E[B(\alpha,\beta,x)],i) = b(n,\frac{\alpha} {\alpha + \beta},i)$$ ?