## code to accompany the rare event example from lecture 1 ## of PSTAT 215A, Bayesian Inference, UCSB ## ## Robert B. Gramacy adapted from Peter Hoff ## plotting the sampling model barplot(rbind(dbinom(0:20, 20, 0.05), dbinom(0:20, 20, 0.1), dbinom(0:20, 20, 0.2)), names=0:20, beside=TRUE, ylab="probability", args.legend=list(x="bottomright", bty="n"), legend.text=c("theta=0.05", "theta=0.1", "theta=0.2")) ## plotting the prior theta <- seq(0,1,length=100) plot(theta, dbeta(theta, 2, 20), type="l", lwd=2, ylab="density", xlab="", bty="n", col="gray") legend(x="right", bty="n", "prior", lwd=2, col="gray") ## plotting the prior and posterior theta <- seq(0,1,length=100) plot(theta, dbeta(theta, 2, 40), type="l", lwd=2, ylab="density", xlab="", bty="n") lines(theta, dbeta(theta, 2, 20), col="gray", lwd=2) legend(x="right", bty="n", c("posterior", "prior"), lwd=2, col=c("black", "gray"))