Estimate the relationship between the probabilities of head of two biased coins

Question: Assume that $$p$$ and $$q$$ were uniformly sampled in $$[0, 1]$$ and two biased coins whose probabilities of head are $$p$$ and $$q$$, respectively, were made. However, we don't know what $$p$$ and $$q$$ are. To estimate them, each coin is tossed $$n$$ times, then we got $$r_1$$ heads for the coin whose probability of head is $$p$$ and $$r_2$$ heads for the other coin as a result. What is the probability that $$p?

I tried Bayes theorem to solve above question. Let $$A$$ and $$B$$ denote

• $$A$$: An event that $$p
• $$B$$: An event that we got the results of tosses as mentioned above

Then $$P(A) = \frac{1}{2} \quad \text{and} \quad P(B) = \binom{n}{r_1}p^{r_1}(1-p)^{n-r_1}\binom{n}{r_2}q^{r_2}(1-q)^{n-r_2}$$ trivially, and what I want to calculate is $$P(A|B)$$. However, I don't have any idea to get $$P(B|A)$$ to use Bayes theorem. How can I solve this?

You are correct that $$P(A)=1/2$$, but your claimed formula for $$P(B)$$ is in fact the formula for $$P(B|p,q)$$, i.e. the probability of the event $$B$$ given that you know $$p$$ and $$q$$. Baye's theorem states that $$P(A|B) = P(B|A) \cdot P(A)/P(B)$$. So you are left with computing $$P(B|A)$$ and $$P(B)$$. This boils down to computing the integral of $$\binom{n}{r_1}p^{r_1}(1-p)^{n-r_1}\binom{n}{r_2}q^{r_2}(1-q)^{n-r_2}$$ over $$p$$ and $$q$$ in the appropriate ranges. You will probably find the Beta function helpful.