% Bayesian Predictive Estimation in Exp/Gamma Model
clear all
close all
  disp('Bayesian Predictive Estimation in Exp/Gamma Model')
  lw = 2; 
  set(0, 'DefaultAxesFontSize', 16);
  fs = 15;
 msize = 10;

%predictive
pred = @(x, n, s, a, b)  (n+a)*(s+b)^(n+a)./(s + b + x).^(n + a + 1);

%data
X = [2.1,  5.5,  6.4,  8.7,  4.9,  5.1,  2.3];

nn=length(X); 
ss = sum(X);
aa = 2;
bb=1;

%prediction
pre = (ss + bb)/(nn + aa - 1)

%variance
varpred = (ss + bb)^2 * (nn + aa)/( (nn+aa -1)^2 * (nn + aa -2))

range = 0:0.01:20;
plot(range, pred(range, nn, ss, aa, bb), 'LineWidth',lw)
hold on
plot([4.5  4.5],[0, 0],'o', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','b', 'MarkerSize',10)
plot([2.1 2.1],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([5.5 5.5],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([6.4 6.4],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([8.7 8.7],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([4.9 4.9],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([5.1 5.1],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([2.3 2.3],[0, 0],'x', 'LineWidth',2, 'MarkerEdgeColor','k','MarkerFaceColor','k', 'MarkerSize',10)
plot([5 5],[0, 0.25],'r--', 'LineWidth',2)

axis tight
%print -depsc 'C:\Springer\Bayes\Bayeseps\predictive.eps'




