Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
8.8 R Code 181 123 124 125 126 127 128 129 130 131 132 133 source("HDIofGrid.R") HDIheight = HDIofGrid( posterior )$height par(new = TRUE) # don't erase previous contour contour( theta1[thindex1] , theta2[thindex2] , posterior[thindex1,thindex2] , main = bquote(.(100*credib)*"% HD region") , levels = signif(HDIheight,3) , lwd = 3 , drawlabels = FALSE , xlab = bquote(theta[1]) , ylab = bquote(theta[2]) ) ## Change next line if you want to save the graph. wantSavedGraph = T # TRUE or FALSE if ( wantSavedGraph ) { dev.copy2eps(file = plotFileName) } 8.8.2 R Code for Metropolis Sampler (Figure 8.3) Important: This program relies on the mvrnorm function in R, which is part of the MASS package. The MASS package is part of the typical distribution of R, and it is probably already installed on your computer. Therefore, the library(MASS) command in this program will load the MASS package with- out complaint. If, however, the program balks at that line, you must install the MASS package. Just uncomment the install.packages command.