Learn R Programming

emdbook (version 1.0.8.1)

HPDregionplot: Plot highest posterior density region

Description

Given a sample from a posterior distribution (an mcmc object from the coda package), plot the bivariate region of highest marginal posterior density for two variables, using kde2d from MASS to calculate a bivariate density.

Usage

HPDregionplot(x, vars = 1:2, h = c(1, 1), n = 50, lump = TRUE, prob = 0.95, xlab = NULL, ylab = NULL, ...)

Arguments

x
an mcmc or mcmc.list object
vars
which variables to plot: numeric or character vector
h
bandwidth of 2D kernel smoother
n
number of points at which to evaluate the density grid
lump
if x is an mcmc.list object, lump the chains together for plotting?
prob
probability level
xlab
x axis label
ylab
y axis label
...
other arguments to contour

Value

  • Draws a plot on the current device, and invisibly returns a list of contour lines (contourLines).

Details

Uses kde2d to calculate a bivariate density, then normalizes the plot and calculates the contour corresponding to a contained volume of prob of the total volume under the surface (a two-dimensional Bayesian credible region).

See Also

HPDinterval in the package, ellipse package library(MASS) library(coda) z <- mvrnorm(1000,mu=c(0,0),Sigma=matrix(c(2,1,1,2),nrow=2)) HPDregionplot(mcmc(z)) hplot