Learn R Programming

extras (version 0.10.0)

xtr_ci_hdi: 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)

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.

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.

See Also

xtr_ci() and xtr_ci_eti()

Examples

Run this code
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

Run the code above in your browser using DataLab