ci_p_hpd | R Documentation |
This function calculates the Highest Posterior Density (HPD) interval for a Binomial proportion using a Bayesian approach. It is vectorized, allowing the evaluation of single values or vectors.
ci_p_hpd(x, n, conf.level = 0.95, prior = "uniform")
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. |
prior |
The prior distribution to use. Options are "uniform" (default) or "jeffreys". |
The HPD interval is a Bayesian credible interval for the Binomial
proportion p
. The posterior distribution is calculated based
on the Beta prior:
- "uniform": \text{Beta}(1, 1)
.
- "jeffreys": \text{Beta}(0.5, 0.5)
.
The limits of the interval are computed using the quantiles of the Beta posterior distribution:
- Lower limit: \text{qbeta}((1 - \text{conf.level}) / 2, \alpha + x, \beta + n - x)
.
- Upper limit: \text{qbeta}(1 - (1 - \text{conf.level}) / 2, \alpha + x, \beta + n - x)
.
A vector with the lower and upper limits.
Omar David Mercado Turizo, omercado@unal.edu.co
Missing reference.
ci_p.
# Example with a single value
ci_p_hpd(x = 15, n = 50, conf.level = 0.95)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.