Bayesian HPD Regions

## Usage

hpdi(object, ...)

# S4 method for numeric
hpdi(object, level = 0.95, CE = TRUE, ...)

# S4 method for MCMC
hpdi(object, level = 0.95, simplify = TRUE, ...)

## Arguments

object

A numeric vector or an MCMC object containing the output of the MCMC algorithm for the parameter.

...

Extra arguments to be passed to stats::density().

level

A length-one numeric vector giving the confidence level.

CE

A logical scalar: are the data expressed in BC/AD years?

simplify

A logical scalar: should the results should be simplified?

## Value

If simplify is TRUE (the default), returns a data.frame giving the lower and upper boundaries of the HPD interval and associated probabilities. Else, returns a list of numeric

matrix.

## References

Hyndman, R. J. (1996). Computing and graphing highest density regions. American Statistician, 50: 120-126. doi:10.2307/2684423 .

stats::density()

Other statistics: credible(), sensitivity(), summary()

## Author

A. Philippe, M.-A. Vibet, T. S. Dye, N. Frerebeau

## Examples

## Coerce to MCMC
eve <- as_events(events, calendar = "CE", iteration = 1)
eve <- eve[1:10000, ]

## CE
credible(eve, level = 0.95) # Credible interval
#>   name     lower     upper    p
#> 1   E1 -1045.210  -202.337 0.95
#> 2   E2 -1979.810 -1613.590 0.95
#> 3   E3  -809.057  -459.090 0.95
#> 4   E4 -1400.040 -1064.290 0.95
hpdi(eve, level = 0.68) # HPD interval
#>   name      lower      upper    p
#> 1   E1 -1009.3026  -774.1160 0.35
#> 2   E1  -490.0595  -257.9273 0.33
#> 3   E2 -1891.7506 -1690.3908 0.68
#> 4   E3  -757.2008  -604.5292 0.68
#> 5   E4 -1311.7275 -1149.4158 0.68

## BP
eve_BP <- CE_to_BP(eve)
credible(eve_BP, level = 0.95) # Credible interval
#>   name    lower    upper    p
#> 1   E1 2994.210 2151.337 0.95
#> 2   E2 3928.810 3562.590 0.95
#> 3   E3 2758.057 2408.090 0.95
#> 4   E4 3349.040 3013.290 0.95
hpdi(eve_BP, level = 0.95) # HPD interval
#>   name    lower    upper    p
#> 1   E1 3010.227 2142.786 0.95
#> 2   E2 3929.877 3558.517 0.95
#> 3   E3 2754.053 2400.858 0.95
#> 4   E4 3355.409 3015.006 0.95