Coin Toss with Prior Distribution for $p$ I am attempting to answer the following question from my actuarial exams:

We are asked to find $P(p=0.5|X=7)$.
Using Bayes Rule, I believe this is
$$P(p=0.5|X=7) = \frac{P(X=7|p=0.5)P(p=0.5)}{P(X=7|p=0.5)P(p=0.5) + P(X=7|p \sim Unif[0.5,1])P(p \sim Unif[0.5,1])}$$
Straightforwardly, using $X \sim Bin(8,p)$:
$$P(X=7|p=0.5)P(p=0.5) = {8 \choose 7}0.5^70.5 \times 0.8$$
I am less sure of $P(X=7|p \sim Unif[0.5,1])P(p \sim Unif[0.5,1])$, if even this is the right expression. Given it's continuous, I thought it might be:
$$P(X=7|p \sim Unif[0.5,1])P(p \sim Unif[0.5,1]) = \int^1_{0.5}{P(x|p)f(p) dp}$$
where $P(x|p) = {8 \choose 7}p^7(1-p)$ and $f(p) = 2$ (being the pdf of $Unif[0.5,1]$). But this doesn't account for the probability of p being uniformly distributed, $P(p \sim Unif[0.5,1]) = 0.2$.
What is the correct way to think about this?
Many thanks
Steven
 A: The question states the prior distributions on the hypotheses as $\pi(H_0)=0.8$ and $\pi(H_1)=0.2$. From Bayes' theorem:
$$
p(H_0\,|\,k)=\frac{P(k\,|\,H_0)\pi(H_0)}{P(k\,|\,H_0)\pi(H_0) + P(k\,|\,H_1)\pi(H_1)}
$$
We observe $k=7$ correct predictions out of $n=8$ total predictions. Using the binomial mass function, we can calculate the posterior as follows:
$$
P(k\,|\,H_0) = {n\choose k}(0.5)^k(1 - 0.5)^{n-k} = {8\choose 7}(0.5)^7(1 - 0.5)^{1} = \frac{1}{32}
$$
and for the alternative hypothesis, we integrate over its range, weighted by the density of the $U(1/2,1)$ distribution (which is $2$):
$$
P(k\,|\,H_1) = \int_{0.5}^{1}2{n\choose k}(p)^k(1 - p)^{n-k}\,\mathrm{d}p = 2\int_{0.5}^{1}{8\choose 7}(p)^7(1 - p)^{1}\,\mathrm{d}p=\frac{251}{1152}
$$
So finally we have:
$$
p(H_0\,|\,7)=\frac{\dfrac{1}{32}0.8}{\dfrac{1}{32}0.8 + \dfrac{251}{1152}0.2} = \frac{144}{395} = 0.364557
$$
A: Great question!  I think your denominator would be better written as
$$P(X=7|p=0.5)\cdot P(p=0.5) $$
$$+\int_{0.5}^1 P(X=7|p= r\cap  0.5<p<1 )\cdot P(p=r|0.5<p<1)\cdot P(0.5<p<1)dr$$.
Let me know if I have made a mistake.  The term $P(p=r|0.5<p<1)$ is the pdf of the uniform distribution over (0.5,1) and the term $P(0.5<p<1)$ would account for the belief mass of 20%.  Here is a related thread asking about how to apply these probability statements to the coin and octopus under investigation.
