summary.post<-function(){ # # Summaries of Bayesian Posterior Distributions # # Note the following will be assumed alpha=2, beta=2 # X=5, n=10 alpha<-2 beta<-2 xx<-seq(0,1,length=100) #plot the prior plot(xx, dbeta(xx,alpha,beta),type="l",lwd=4,lty=2,ylim=c(0,4.5)) x<-5 n<-10 alphastar<-alpha+x betastar<-beta+(n-x) #plot the posterior lines(xx,dbeta(xx,alphastar,betastar),lwd=4,lty=1) # a different prior -- alpha=10, beta=10 alpha<-10 beta<-10 #plot the new prior lines(xx,dbeta(xx,alpha,beta),lwd=3,col="red",lty=2) alphastar<-alpha+x betastar<-beta+(n-x) #plot the new posterior lines(xx,dbeta(xx,alphastar,betastar),lwd=3,col="red",lty=1) # now summarize!! alpha<-2 beta<-2 alphastar<-alpha+x betastar<-beta+(n-x) postmean<-alphastar/(alphastar+betastar) postvar<-alphastar*betastar/((alpha+beta+1)*(alphastar+betastar)^2) poststd<-sqrt(postvar) postmedian<-qbeta(.5,alphastar,betastar) postmode<-NULL return(postmean,postvar,poststd,postmedian,postmode) }