Last chance! 50% off unlimited learning
Sale ends in
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.
HPDregionplot(x, vars = 1:2, h, n = 50, lump = TRUE, prob = 0.95, xlab =
NULL, ylab = NULL, lims=NULL, ...)
Draws a plot on the current device, and
invisibly returns a list of contour lines (contourLines
).
an mcmc
or mcmc.list
object
which variables to plot: numeric or character vector
bandwidth of 2D kernel smoother (previous default value was c(1,1)
,
which worked poorly with some plots with very small scales;
if not specified, defaults to values in kde2d
)
number of points at which to evaluate the density grid
if x
is an mcmc.list
object, lump the
chains together for plotting?
probability level
x axis label
y axis label
limits, specified as (x.lower,x.upper,y.lower,y.upper)
(passed to kde2d
)
other arguments to contour
Ben Bolker
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).
HPDinterval
in the coda
package,
ellipse
package
library(MASS)
library(coda)
z <- mvrnorm(1000,mu=c(0,0),Sigma=matrix(c(2,1,1,2),nrow=2))
z2 <- mvrnorm(1000,mu=c(0,0),Sigma=matrix(c(2,1,1,2),nrow=2))
HPDregionplot(mcmc(z))
HPDregionplot(mcmc.list(mcmc(z),mcmc(z2)))
Run the code above in your browser using DataLab