% "Two-headed coin"
%
% Out of N coins one is with two heads. A coin is selected
% at random and flipped k times and k times heads appeared.
% What is the probability that the coin with two heads was
% selected?
% 
%
clear all
close all


  disp('Two Headed Coin')
  lw = 3; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
  msize = 10;
  

N=1000000; %number of coins N-1 fair, 1 two-headed
%
 p=[];  %keep posterior probs here
for k=1:40
    p = [p  2^k/(2^k + N - 1)];
end
figure(1)
plot((1:40), p, 'linewidth', lw)
hold on
plot((1:40), p, 'o', 'markersize', msize,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','g')

plot(16, p(16), 'ro', 'markersize', msize,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r')
   
plot(24, p(24), 'ro', 'markersize', msize,...
                'MarkerEdgeColor','k',...
                'MarkerFaceColor','r')   
ylabel('Posterior probability of a 2H coin')
xlabel('Number of flips all resulting in H')
%print -depsc 'C:\BESTAT\Probs\Probseps\twoheaded.eps'

figure(2)
op =  p./(1-p);
semilogy((1:40),op, 'linewidth', lw)
hold on
semilogy((1:40), op, 'o', 'markersize', msize)
ylabel(' Posterior Odds')
xlabel('Number of flips all resulting in H')
%print -depsc 'C:\Springer\Probs\Probseps\twoheaded.eps'



