Computes highest density intervals (HDIs) for a numeric sample. The HDI is defined as the shortest interval containing a target probability mass.
Usage
hdi(x, ...)
# Default S3 method
hdi(x, probs = c(0.5, 0.99), ...)Value
A list with class "koma_hdi" containing:
- intervals
Named list of matrices with columns
lowerandupper, one matrix perprobslevel.- mode
Sample median of the draws (used as a center reference).
- cutoff
Named numeric vector of
NAvalues (not defined for HDI).- mass
Named numeric vector of achieved mass for each level.
- probs
Numeric vector of target masses in (0, 1].
Examples
x <- rnorm(1000)
hdi(x, probs = c(0.5, 0.9))
#> ==========
#> level_50
#> --------
#> Median: 0.001
#> Intervals: [-0.626; 0.68]
#>
#> level_90
#> --------
#> Median: 0.001
#> Intervals: [-1.55; 1.714]
#>
#> ==========
#> Median, [HDI]
data("simulated_sem")
set.seed(11)
fit <- estimate(
ts_data = simulated_sem$ts_data,
sys_eq = simulated_sem$sys_eq,
dates = simulated_sem$dates,
options = list(gibbs = list(ndraws = 10))
)
#>
#> ── Gibbs Sampler Settings ──────────────────────────────────────────────────────
#>
#> ── System Wide Settings ──
#> • Number of draws (`ndraws`): 10
#> • Burn-in ratio (`burnin_ratio`): 0.5
#> • Burn-in (`burnin`): 5
#> • Store frequency (`nstore`): 1
#> • Number of saved draws (`nsave`): 5
#> • Tau (`tau`): 1.1
#>
#>
#> ── Estimation ──────────────────────────────────────────────────────────────────
hdi_fit <- hdi(fit, probs = c(0.5, 0.9))
names(hdi_fit$intervals)
#> [1] "consumption" "investment" "current_account" "manufacturing"
#> [5] "service"