% Bayes Test of Precise H0: theta=1/2 vs H1: theta =/= 1/2
%Coin flipped 12 times, 10 heads. Prior probabilities of hpotheses equal.
%For thetas from H1, beta Be(4,4) prior.
theta0=1/2; n=12; x= 10; alpha=4; beta = 4; pi0=1/2; pi1=1-pi0;
pH0 = (1 + pi1/pi0 * gamma(alpha + beta)/gamma(alpha)/gamma(beta) * ...
    (gamma(alpha + x) * gamma(beta + n - x)/gamma(alpha + beta + n))/   ...
   ( theta0^x * (1-theta0)^(n-x) )   )^(-1)      %0.2211

z=(x - n * theta0)/sqrt(n * theta0 * (1-theta0))
pval = 2 * (1-normcdf(z))      % 0.0209


