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)

Arguments

x

A number or a vector with the number of successes.

n

A number or a vector with the number of trials.

conf.level

Confidence level for the returned confidence interval. By default, it is 0.95.

Value

A vector with the lower and upper limits of the HPD interval.

Details

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.

See also

Author

Rusvelt Jose Meza San Martín, rmezas@unal.edu.co

Examples

# 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