hdi: Calculate the highest density interval

Description Usage Arguments Details Value Examples

View source: R/hdp.r

Description

Calculate the highest density interval (HDI).

Usage

1
hdi(dens, alpha = 0.05)

Arguments

dens

an estimated density, such as the one returned by the [stats::density()] function, with x and y values describing the shape of the density

alpha

the size of both tails or 1 - interval

Details

The HDI is the shortest interval with the required density. Note that in general, HDI can be split into several subintervals if te underlying distribution is multimodal. This function however provide only continuous HDI.

Also note that the HDI intervals, unlike the more common equal-tailed intervals, are not invariant under non-linear transformations.

Value

upper and lower bounds for a selected HDI interval

Examples

1
2
3
4
x = rnorm(100)
dens = density(x)
hdi(dens, alpha=0.05) # the 95% HDI
hdi(dens, alpha=0.5) # the 50% HDI

bioDS/phyloRNA documentation built on Feb. 21, 2022, 3:28 p.m.