ci_p_hpd: Highest Posterior Density (HPD) interval for Binomial...

View source: R/ci_p_xxx.R

ci_p_hpdR Documentation

Highest Posterior Density (HPD) interval for Binomial proportion

Description

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.

Usage

ci_p_hpd(x, n, conf.level = 0.95, prior = "uniform")

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.

prior

The prior distribution to use. Options are "uniform" (default) or "jeffreys".

Details

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).

Value

A vector with the lower and upper limits.

Author(s)

Omar David Mercado Turizo, omercado@unal.edu.co

References

Missing reference.

See Also

ci_p.

Examples

# Example with a single value
ci_p_hpd(x = 15, n = 50, conf.level = 0.95)

fhernanb/stests documentation built on March 29, 2025, 10:36 a.m.