Package 'bssbinom'

Title: Bayesian Sample Size for Binomial Proportions
Description: Computation of the minimum sample size using the Average Coverage Criterion or the Average Length Criterion for estimating binomial proportions using beta prior distributions. For more details see Costa (2025) <DOI:10.1007/978-3-031-72215-8_14>.
Authors: Eliardo Costa [aut, cre] (ORCID: <https://orcid.org/0000-0003-4528-0379>)
Maintainer: Eliardo Costa <[email protected]>
License: MIT + file LICENSE
Version: 1.0.0
Built: 2026-06-01 11:44:57 UTC
Source: https://github.com/eliardocosta/bssbinom

Help Index


HD interval for the beta distribution

Description

Computes the highest density interval for the beta distribution by optimization or simulation.

Usage

hd.beta(c, d, rho = NULL, len = NULL, N = 1000)

Arguments

c

First parameter of the beta distribution.

d

Second parameter of the beta distribution.

rho

A number in (0, 1) representing the fixed probability for the HD interval.

len

A positive real number representing the fixed length for the HD interval.

N

Number of replicates used in the simulation when the length is fixed. Default is 1000.

Value

Lower and upper bounds of the HD interval.

Note

For fixed probability (rho) of the HD interval the function uses betaHPD function from pscl R package. For fixed length of the HD interval the function uses an algorithm proposed in M'Lan et al. (2006).

References

Costa, E. G. (2025). Bayesian Sample Size for Binomial Proportions with Applications in R. In: Awe, O.O., A. Vance, E. (eds) Practical Statistical Learning and Data Science Methods. STEAM-H: Science, Technology, Engineering, Agriculture, Mathematics & Health. Springer, Cham. doi:10.1007/978-3-031-72215-8_14.

M’Lan, C.E., Joseph, L., Wolfson, D.B. (2006). Bayesian sample size determination for case-control studies. Journal of the American Statistical Association, 101, 760–772.

Examples

# HD interval with probability 0.95 for Beta(2, 3)
hd.beta(c = 2, d = 3, rho = 0.95)

# HD interval with length 0.3 for Beta(2, 3)
hd.beta(c = 2, d = 3, len = 0.3)

HD interval for the difference of two beta distributions

Description

Computes the highest density interval for the difference of two beta distributions by simulation.

Usage

hd.diffbetas(c1, d1, c2, d2, rho = NULL, len = NULL, N = 1000)

Arguments

c1

First parameter of the beta distribution of the first proportion.

d1

Second parameter of the beta distribution of the first proportion.

c2

First parameter of the beta distribution of the second proportion.

d2

Second parameter of the beta distribution of the second proportion.

rho

A number in (0, 1) representing the fixed probability for the HD interval.

len

A positive real number representing the fixed length for the HD interval.

N

Number of replicates used in the simulation. Default is 1000.

Value

Lower and upper bounds of the HD interval.

Note

For fixed probability (rho) of the HD interval the function uses emp.hpd function from TeachingDemos R package. For fixed length of the HD interval the function uses an algorithm proposed in M'Lan et al. (2006).

References

Costa, E. G. (2025). Bayesian Sample Size for Binomial Proportions with Applications in R. In: Awe, O.O., A. Vance, E. (eds) Practical Statistical Learning and Data Science Methods. STEAM-H: Science, Technology, Engineering, Agriculture, Mathematics & Health. Springer, Cham. doi:10.1007/978-3-031-72215-8_14.

M’Lan, C.E., Joseph, L., Wolfson, D.B. (2006). Bayesian sample size determination for case-control studies. Journal of the American Statistical Association, 101, 760–772.

Examples

hd.diffbetas(c1 = 8, d1 = 2, c2 = 2, d2 = 8, rho = 0.95)

hd.diffbetas(c1 = 8, d1 = 2, c2 = 2, d2 = 8, len = 0.2)

Minimum sample size for a single binomial parameter with a beta prior distribution

Description

Minimum sample size for a single binomial parameter with a beta prior distribution

Usage

mss.bb(
  crit,
  c,
  d,
  rho.min = NULL,
  len = NULL,
  rho = NULL,
  len.max = NULL,
  R = 1000,
  n0 = 1
)

Arguments

crit

A character string specifying the criterion. Criteria: "ACC", "ALC" and "ALCApprox".

c

First parameter of the beta prior distribution.

d

Second parameter of the beta prior distribution.

rho.min

A number in (0, 1) representing the minimum admissible posterior probability for the HPD interval in the ACC.

len

A positive real number representing the length of the HPD interval in the ACC.

rho

A number in (0, 1) representing the posterior probability of the HPD in the ALC.

len.max

A positive real number representing the maximum admissible length for the HPD interval in the ALC.

R

Number of replicates used in the simulation. Default is 1000.

n0

A positive integer, n0+1 is the initial sample size in which the function will check the criterion. Default is 1.

Value

An integer representing the sample size.

Note

Depending on the fixed values for interval length and probability, the function may take a while to calculate the sample size. ALC tends to be faster than ACC. Since this function uses Monte Carlo simulations, the provided minimum sample sizes may vary from one call to the next. The difference is expected to decrease as the number of replicates (R) used in the Monte Carlo simulation increases. For the criterion "ALCApprox" it is used the result of Theorem 4.1 of M'Lan et al. (2008).

References

Costa, E. G. (2025). Bayesian Sample Size for Binomial Proportions with Applications in R. In: Awe, O.O., A. Vance, E. (eds) Practical Statistical Learning and Data Science Methods. STEAM-H: Science, Technology, Engineering, Agriculture, Mathematics & Health. Springer, Cham. doi:10.1007/978-3-031-72215-8_14.

M’Lan, C.E., Joseph, L., Wolfson, D.B. (2008). Bayesian sample size determination for binomial proportions. Bayesian Analysis, 3, 269–296.

Examples

mss.bb(crit = "ALC", c = 10, d = 2, rho = 0.9, len.max = 0.25)

mss.bb(crit = "ALCApprox", c = 10, d = 2, rho = 0.9, len.max = 0.25)

## Not run: mss.bb(crit = "ACC", c = 2, d = 10, rho.min = 0.9, len = 0.25)