Cumulative Distribution Function of the Difference Between Two Beta-Binomial Variables
Source:R/pBetaBinomdiff.R
pBetaBinomdiff.Rd
This function calculates the cumulative distribution function (CDF) of the difference between two independent beta-binomial random variables. Specifically, it computes P((Y1/m1) - (Y2/m2) > q) where Y1 ~ BetaBinomial(m1, alpha1, beta1) and Y2 ~ BetaBinomial(m2, alpha2, beta2).
Arguments
- q
A numeric value representing the quantile threshold for the proportion difference.
- m1
A positive integer representing the number of trials for the first beta-binomial distribution.
- m2
A positive integer representing the number of trials for the second beta-binomial distribution.
- alpha1
A positive numeric value representing the first shape parameter of the first beta distribution.
- alpha2
A positive numeric value representing the first shape parameter of the second beta distribution.
- beta1
A positive numeric value representing the second shape parameter of the first beta distribution.
- beta2
A positive numeric value representing the second shape parameter of the second beta distribution.
Value
A numeric value representing P((Y1/m1) - (Y2/m2) > q), the probability that the difference in proportions between the two beta-binomial variables exceeds the quantile q.
Details
The function uses the probability mass functions of beta-binomial distributions to compute the exact probability. The beta-binomial distribution arises when the success probability in a binomial distribution follows a beta distribution, making it useful for modeling overdispersed count data.
The probability mass function for BetaBinomial(m, α, β) is: $$P(Y = k) = \binom{m}{k} \frac{B(k + \alpha, m - k + \beta)}{B(\alpha, \beta)}$$
where B(·,·) is the beta function.
Examples
# Calculate P((Y1/12) - (Y2/12) > 0.2) for symmetric beta priors
pBetaBinomdiff(0.2, 12, 12, 0.5, 0.5, 0.5, 0.5)
#> [1] 0.3372581
# Calculate P((Y1/20) - (Y2/15) > 0.1) for different sample sizes
pBetaBinomdiff(0.1, 20, 15, 1, 1, 1, 1)
#> [1] 0.4017857
# Calculate P((Y1/10) - (Y2/10) > 0) for informative priors
pBetaBinomdiff(0, 10, 10, 2, 3, 3, 2)
#> [1] 0.2383331