hpd_mult: hpd_mult

Description Usage Arguments Details See Also Examples

Description

Compute the highest density posterior region from a (possibly multi-modal) sample of points.

Usage

1
2
hpd_mult(x, dens, prob = 0.95, tol, force_uni = FALSE,
  interactive = FALSE)

Arguments

x

vector of samples from some distribution

dens

a density object based on x, defaults to density(x)

prob

numeric in (0, 1) the probability that the interval should be

tol

numeric, smaller means longer compute time, but more accurate results

force_uni

Logical, should the function be forced to return a single interval? Defaults to FALSE.

interactive

logical, defaults to FALSE. If TRUE, a fun plot is shown and the function's process of choosing the region is displayed. The user hits enter to proceed through.

Details

Since hpd_mult relies on a density object, it is possible to be returned a result that is outside the bounds of the data (i.e., an hpd for a beta random variable that has a left end point below 0).

A random horizontal line is repeatedly generated and the points along the line that cross dens$y are calculated. These points make up a proposed hpd region whose area is computed. Given this area, a new horizontal line is generated until the area is close to prob (within tol).

The option force_uni == TRUE is meant to be a replacement for hpd_uni(), since that function can take a long time to run.

See Also

hpd_uni

Examples

1
2
3
set.seed(1)
x = c(rnorm(100), rnorm(100, 5)
hpd = hpd_mult(x)

mickwar/mwBASE documentation built on May 22, 2019, 9:56 p.m.