%LMex050802_4th.m
hold off; cla;clf
theta=0:0.001:1;
Density=betapdf(theta,2,4)
plot(theta,Density,'r','Linewidth',3);
ylabel('Density','FontSize',20)
title('Figure 5.8.1a','FontSize',22)
xlabel('theta','FontSize',20)
figure(gcf);pause
Prior=betapdf(theta,4,102)
plot(theta,Prior,'--r','Linewidth',3);
ylabel('Density','FontSize',20)
title('Figure 5.8.1b','FontSize',22)
xlabel('theta','FontSize',20)
axis([0 0.1 0 35])
figure(gcf)
hold on;
% A work in progress to plot the posterior pdf as a function of k
% Let's assume k=4 and n=100, what is the posterior.
k=4;n=100;
% Posterior=factorial(n+105)./(factorial(k+3).*factorial(n-k+101)).*theta.^(k+3).*(1-theta).^(n-k+101);
Posterior=exp(gammaln(n+106)-gammaln(k+4)-gammaln(n-k+102))*theta.^(k+3).*(1-theta).^(n-k+101);
plot(theta,Posterior,'m','Linewidth',3);figure(gcf)
legend('Prior','Posterior')
hold off