In one of the homework problems, you are asked to do a Bayesian sensitivity analysis for a posterior probability with respect to the prior. Specifically, suppose we are interested in learning about a proportion and we wish to compute the posterior probability
It is easy to construct a contour plot to illustrate this sensitivity analysis on R.
1. First we set up a grid of values of
eta = seq(.1, .9, by=.1) K = c(1, 2, 8, 16, 32)
2. Next we write a short function that computes the posterior probability
myfun=function(eta, K) 1 - pbeta(.5, K*eta+ 25, K*(1-eta) + 40)
3. We now use the outer function to compute this probability on all combinations of
PROB = outer(eta, K, myfun)
4. Last, we use the contour function with inputs the two vectors and the matrix of probabilities. We can specify which levels to draw on the contour graph.
contour(eta, K, PROB, levels=c(0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.95), xlab="eta", ylab="K", main="P(theta > 0.5)")