hpd_mult: hpd_mult (by Mickey Warner)

Description Usage Arguments Details See Also Examples

View source: R/hpd_mult.R

Description

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

Usage

1
hpd_mult(x, dens, prob = 0.95, tol, 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

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

See Also

get.hpd

Examples

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

luiarthur/rcommon documentation built on Jan. 18, 2021, 12:45 a.m.