Bayesian test on Poisson Distribution $\newcommand{\Po}{\operatorname{Poisson}}$I have $X$ the observed count, and $\theta_0$ the expected count. For instance $X=20$ and $\theta_0=9.8$.
To compute the p-value, I just need to compute:
$P(X \geq x)=\sum_{i=x}^\infty \Po(i\mid\theta_0)$
with $H_0:\theta = \theta_0$ and $H_1:\theta > \theta_0$.
I get :
ppois(20,9.8,lower.tail=F)
[1] 0.00125043

Now I want to use a Bayesian approach because I know the prior probability of $H_1$, $P(H_1)$. I have no prior information regarding the shape/parameters of the distribution of $\theta$, $P(\theta)$. Maybe a uniform prior on $[0,a]$. By the way, I have no idea how to determine $a$.
I would like to compute the Bayes factor and the posterior probability $P(H_1 \mid X)$. I think the key is to compute the marginal likelihood $\int_0^\infty \Po(X\mid\theta) P(\theta)\,d\theta$, which can be used to compute the Bayes Factor:
$$BF=\frac{\Po(X\mid\theta_0)}{\int_0^\infty \Po(X\mid\theta) P(\theta) \, d\theta}$$
I know I can use the gamma distribution as prior conjugate, but I don't know more details. How to do it? Is there any close form solution. If yes what is it? Do you have any example in R?
Thanks!
 A: First,
ppois(20,9.8,lower.tail=FALSE)

actually computes $P(X>20 | \theta=9.8)$ rather than $P(X\ge 20 | \theta=9.8)$. So to compute the p-value for $H_0$ vs $H_1$ you actually need
> ppois(20-0.5,9.8,lower.tail=FALSE)
[1] 0.002772067

Subtracting 0.5 is a trick to ensure that $x=20$ is included in the right tail.
Second, you can't use a uniform or a gamma prior for $\theta$ because your prior information rules them both out. The fact that $H_0$ and $H_1$ are the only two possibilities guarantees that $\theta \ge \theta_0$. On the other hand, either a gamma prior or the uniform prior you suggested would permit small positive values for $\theta$, including values less than $\theta_0$. If you were to specify a prior correctly, it would have to be truncated at $\theta_0$. Moreover it would have to have mass at $\theta=\theta_0$. These requirements make it impossible for you to specify a prior that would yield a closed for posterior distribution for $\theta$.
You say that you have a prior probability for $H_0$, let's call it $\pi_0$. You also have the p-value $p_0 = P(X\ge x|H_0$).
Can you also come up with a reasonable value for the probability that $X$ exceeds 20 under the alternative hypothesis, i.e., for $p_1 = P(X \ge x| H_1)$? If you can, then you can proceed like this. You know that
$$P(H_1|X\ge x)=\frac{P(X\ge x| H_1) P(H_1)}{P(X\ge x)}=\frac{p_1(1-\pi_1)}{P(X\ge x)}$$
You also know that 
$$P(H_0|X\ge x)=\frac{P(X\ge x| H_0) P(H_0)}{P(X\ge x)}=\frac{p_0\pi_0}{P(X\ge x)}$$
Therefore the Bayes factor is
$$BF=\frac{P(H_1|X\ge x)}{P(H_0|X\ge x)}=\frac{p_1 (1-\pi_0)}{p_0\pi_0}$$
which is computable. Finally,
$$P(H_1 | X\ge x) = \frac{BF}{1-BF}$$
