xtr_ci_hdi: Highest Density Interval

View source: R/ci_hdi.R

xtr_ci_hdiR Documentation

Highest Density Interval

Description

Calculates Bayesian credible intervals using the highest density interval (HDI), i.e., the narrowest CI with the specified minimum coverage.

Usage

xtr_ci_hdi(x, level = 0.95, ..., na_rm = FALSE)

Arguments

x

A numeric vector of MCMC samples.

level

A number > 0 and <= 1 specifying the probability coverage of the interval.

...

Currently unused.

na_rm

A flag indicating whether to remove missing values.

Value

A data.frame of the lower and upper limits for the credible interval. Note that the interval is not guaranteed to be one-sided or two-sided. Returns integer limits if the input data are integers and double otherwise.

See Also

xtr_ci() and xtr_ci_eti()

Examples

xtr_ci_hdi(1:10, level = 0.1) # only 10% of values inside
xtr_ci_hdi(1:10, level = 0.2) # only 20% of values inside
xtr_ci_hdi(1:10, level = 0.2 + 0.01) # at least 20.1% of values inside
xtr_ci_hdi(1:100) # inclusive interval [3, 98] with 95% of values inside

extras documentation built on July 16, 2026, 1:07 a.m.