R/ci_p_xxx.R
ci_p_jeffreys.Rd
This function calculates the confidence interval for a proportion. It is vectorized, allowing users to evaluate it using either single values or vectors.
ci_p_jeffreys(x, n, conf.level = 0.95)
A vector with the lower and upper limits.
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}(x+0.5, n-x+0.5)$$
The limits of the Bayesian confidence interval are derived from the quantiles of the posterior distribution:
$$\text{Lower Limit}=B_{1-\alpha/2, x+0.5, n-x+0.5}$$
$$\text{Upper Limit}=B_{\alpha/2, x+0.5, n-x+0.5}$$
where \(B_{\omega, a, b}\) is the \(100\%(1-\omega)\) percentile of the Beta distribution with parameters \(a\) and \(b\).
# Example with a single value
ci_p_jeffreys(x=5, n=20, conf.level=0.95)
#> [,1]
#> [1,] 0.1023985
#> [2,] 0.4641946
# Example with vectors
x_values <- c(5, 10, 15)
n_values <- c(20, 30, 40)
ci_p_jeffreys(x=x_values, n=n_values, conf.level=0.95)
#> [,1] [,2] [,3]
#> [1,] 0.1023985 0.1859788 0.2379065
#> [2,] 0.4641946 0.5111481 0.5294649