Saturday, September 10, 2011

plotPost.R now has curve option (instead of histogram)

When plotting the distribution formed by an MCMC chain, the book uses a histogram. I've added a new option to the plotPost.R function so that it can make a curve instead. Get the new plotPost.R program from the book's web site.

An example. Suppose x is the vector of values in an MCMC chain:

x = rnorm( 10000 , 2.15 , 1 ) 
The usual plotPost would produce a histogram, like this:
histinfo = plotPost( x , breaks=30 , col="skyblue" , compVal= 0 , ROPE=c(-0.1,0.1) )
But the new plotPost has a showCurve option: 
histinfo = plotPost( x , showCurve=T , col="skyblue" , compVal= 0 , ROPE=c(-0.1,0.1) )

Notice that the "breaks" argument was removed from the command when using showCurve=T, because "breaks" only applies to histograms.
Why use one form or the other? A histogram reminds the viewer that the plot represents a sample of points, not a known mathematical function (even though there is a mathematical function underlying the sample). This was the motivation for using histograms in the book. Also, the curve uses a kernel density estimation technique that blurs the distribution, so the curve will tend to be not quite peaked enough and a little too wide in its tails. On the other hand, the curve might be easier to view and more aesthetically pleasing. Ultimately the choice is yours.  Now you have the choice!

No comments:

Post a Comment