n = 100; phi = 1; mu = 5
theta.t = rgamma(n,phi,phi/mu)
y = rpois(n, theta.t)
a = 1; b = 1;
t.obs = var(y)
nT = 10000
t.pred = rep(NA, nT)
for (t in 1:nT) {
theta.post = rgamma(1, a + sum(y),
b + n)
y.pred = rpois(n, theta.post)
t.pred[t] = var(y.pred)
}
hist(t.pred,
xlim = range(c(t.pred, t.obs)),
xlab="var",
main="Posterior Predictive Distribution")
abline(v = t.obs, col="red")