- Posterior Analysis
- Activity
- Integration Versus Simulation
Derive the posterior densities for a Poisson sample with a Gamma prior, and for an exponential sample with a Gamma prior. Do you recognize these densities?
R
.set.seed(1) # For reproducibility y <- rnorm(10000); w <- as.numeric(y>1) prob.est <- mean(w); sd.est <- sd(w) / sqrt(length(w)) round(c(prob.est, sd.est), 4)
## [1] 0.1636 0.0037
n <- 10000 t1 <- rbeta(n, (1+32), (1+80-32)) t2 <- rbeta(n, (2+35), (1+100-35)) gamma <- t1-t2 w <- as.numeric(gamma>0) prob.est <- mean(w) sd.est <- sd(w) / sqrt(length(w)) round(c(prob.est, sd.est), 4)
## [1] 0.7185 0.0045
gamma.density <- density(gamma) plot(gamma.density, main="Marginal Posterior Distribution")