Compute Highest Posterior Density Intervals
hpd.RdCompute the Highest Posterior Density Interval (HPD) from an inverse density function (hpd) or a vector of realizations of the distribution (emp.hpd).
Arguments
- posterior.icdf
Function, the inverse cdf of the posterior distribution (usually a function whose name starts with 'q').
- x
A vector of realizations from the posterior distribution.
- conf
Scalar, the credible level desired.
- tol
Scalar, the tolerance for
optimize.- ...
Additional arguments to
posterior.icdf.- lower
Optional lower bound on support of x.
- upper
Optional upper bound on support of x.
Details
These functions compute the highest posterior density intervals
(sometimes called minimum length confidence intervals) for a Bayesian
posterior distribution. The hpd function is used when you have
a function representing the inverse cdf (the common case with
conjugate families). The emp.hpd function is used when you
have realizations of the posterior (when you have results from an MCMC
run).
Author
Greg Snow 538280@gmail.com
Note
These functions assume that the posterior distribution is unimodal, they compute only 1 interval, not the set of intervals that are appropriate for multimodal distributions.
Examples
hpd(qbeta, shape1=50, shape2=250)
#> [1] 0.1253598 0.2092238
tmp <- rbeta(10000, 50, 250)
emp.hpd(tmp)
#> [1] 0.1254119 0.2084626