# Correct numerical result in Bayesian model comparison

I was wondering how to calculate the following Bayesian model comparison.

Suppose you have a couple of models:

$$M_{1}: x \sim Bin(n, \pi); p \sim Be(1,1)$$ $$M_{2}: x \sim Bin(n, \pi); p \sim Be(30,30)$$

Congdon's book says this:

As a toy example, consider comparing two beta priors, $p ∼ Be(\alpha, \beta)$, for a binomial probability, when the data are x = 1 sucesses in n = 10 trials.

This choice can be solved analytically to give $P(M_1 |x) = 0.8634$. In particular, integrating $\pi$ out from the binomial-beta mixture model, $x \sim Bin(n, π)$, $π \sim Be(\alpha, \beta)$, gives a beta-binomial distribution, $x ∼ Beta−Bin(n, \alpha, \beta)$, with density:

$$p(x|n,\alpha, \beta)= \frac{Be(x+\alpha, n-x+\beta)}{Be(\alpha, \beta)}Bin(n, x)$$ which can be evaluated at $p(x|10, 1, 1)$ and $p(x|10, 30, 30)$

where $Beta-Bin$ is the Beta-Binomial distribution.

I was assuming that $P(M_{1}|x)$ was calculated in the following way:

$$P(M_{1}|x) \propto P(M_{1})p(x|M_{1}) = P(M_{1})\int _{0}^{1}p(x|\pi,M_{1})p(\pi|M_{1})d\pi$$

In the equation above, $p(x|\pi,M_{1})$ should be the likelihood $Bin(n,\pi)$ and the second term $p(\pi|M_{1})$ is the prior $Beta(1,1)$ under model $M_{1}$.

The integral $\int _{0}^{1}p(x|\pi,M_{1})p(\pi|M_{1})d\pi$ is simply

$$\int _{0}^{1}Bin(n,\pi)Beta(1,1)d\pi=\int_{0}^{1}\binom{n}{x}p^{x}(1-p)^{n-x}\frac{p^{\alpha-1}(1-p)^{\beta-1}}{B(\alpha,\beta)}dp = \frac{Be(x+\alpha, n-x+\beta)}{Be(\alpha,\beta)}\binom{n}{x}$$

However, even though I obtain the result described in the quote as $p(x|n,\alpha, \beta)$ after solving the integral, I don't get the correct numerical result (assuming $P(M_{1})=0.5$ and after normalizing both $P(M_{1}|x)$ and $P(M_{2}|x)$)

Does anyone know how to obtain the correct result?

• What is the observed $x$? Oct 14, 2014 at 15:43
• Oh, sorry. It is supposed to be $x=1$ and $n=10$. Let me add that part too. Oct 14, 2014 at 15:49
• Add also the computations and values you obtain for $P(x \mid M_i)$ and $P(M_i \mid x)$. Oct 14, 2014 at 15:54
• Damn, turns out that now I get the correct result! Maybe I miscalculated something the first time. I will update it anyway. Oct 14, 2014 at 16:15

It seems I miscalculated something the first time. Now I get the correct answer. Basically, I did the following calculation (again assuming $P(M_1) = P(M_2) = 0.5$):
$$\frac{P(M_{1}|x)}{P(M_{2}|x)} = \frac{P(M_{1})p(x|M_{1})}{P(M_{2})p(x|M_{1})} =\frac{p(x|M_{1})}{p(x|M_{2})}=\frac{0.0909091}{0.014382}$$
However, since this is not normalized, $0.0909091+0.014382=0.105291$ and recompute each value: