Extract confidence intervals from a vector of samples

extract_ci(x, CI_level = seq(0.1, 0.9, 0.1), type = c("eti", "hdi"))

Arguments

x

Vector of samples from a distribution.

CI_level

Vector containing the level of the confidence/credible intervals.

type

"eti" for equal-tailed intervals and "hdi" for highest density intervals.

Value

Dataframe with columns: Lower, Upper, Level.

Examples

x <- rexp(1e4)
extract_ci(x, type = "eti")
#>          Lower     Upper Level
#> 45% 0.60214888 0.8010835   0.1
#> 40% 0.50519085 0.9145090   0.2
#> 35% 0.42638856 1.0460463   0.3
#> 30% 0.35376673 1.2088966   0.4
#> 25% 0.28359643 1.3916396   0.5
#> 20% 0.22018621 1.6108243   0.6
#> 15% 0.15937483 1.9256560   0.7
#> 10% 0.10268709 2.3326621   0.8
#> 5%  0.04981487 2.9701352   0.9
extract_ci(x, type = "hdi")
#>          Lower     Upper Level
#> 1 0.0026591378 0.1043563   0.1
#> 2 0.0031503781 0.2220309   0.2
#> 3 0.0004003387 0.3539455   0.3
#> 4 0.0005700634 0.5053467   0.4
#> 5 0.0001831493 0.6990303   0.5
#> 6 0.0007303427 0.9147638   0.6
#> 7 0.0005700634 1.2100653   0.7
#> 8 0.0004003387 1.6109634   0.8
#> 9 0.0001831493 2.3338180   0.9