R/ci_p_xxx.R
ci_p_hpd_jeffreys.Rd
This function calculates the Highest Posterior Density (HPD) interval for a Binomial proportion using Jeffreys prior. It is vectorized, allowing the evaluation of single values or vectors.
ci_p_hpd_jeffreys(x, n, conf.level = 0.95)
A vector with the lower and upper limits of the HPD interval.
The Jeffreys prior is a non-informative prior (\(Beta(0.5, 0.5)\)) based on the Fisher information. The posterior distribution is Beta:
$$p | x \sim \text{Beta}(0.5 + x, 0.5 + n - x)$$
The HPD interval is calculated using the posterior samples from the Beta distribution:
$$ \text{HPD Interval}=[L, U]$$
where \(L\) and \(U\) are the bounds of the smallest interval containing \(1 - \alpha\) posterior probability.
ci_p.
# Example with a single value
ci_p_hpd_jeffreys(x=5, n=20, conf.level=0.95)
#> [,1]
#> [1,] 0.08992554
#> [2,] 0.44654470
# Example with vectors
x_values <- c(5, 10, 15)
n_values <- c(20, 30, 40)
ci_p_hpd_jeffreys(x=x_values, n=n_values, conf.level=0.95)
#> [,1] [,2] [,3]
#> [1,] 0.08992554 0.1795676 0.2341161
#> [2,] 0.44654470 0.5035473 0.5252455