Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

hpd

Compute Highest Posterior Density Intervals


Description

Compute the Highest Posterior Density Interval (HPD) from an inverse density function (hpd) or a vector of realizations of the distribution (emp.hpd).

Usage

hpd(posterior.icdf, conf=0.95, tol=0.00000001,...)

emp.hpd(x, conf=0.95)

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 confidence level desired.

tol

Scalar, the tolerance for optimize.

...

Additional arguments to posterior.icdf.

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).

Value

A vector of length 2 with the lower and upper limits of the interval.

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.

Author(s)

Greg Snow 538280@gmail.com

See Also

hdr in the hdrcde package.

Examples

hpd(qbeta, shape1=50, shape2=250)

tmp <- rbeta(10000, 50, 250)
emp.hpd(tmp)

TeachingDemos

Demonstrations for Teaching and Learning

v2.12
Artistic-2.0
Authors
Greg Snow
Initial release
2020-04-01

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.