
Cumulative Distribution Function of the Difference Between Two Independent Beta-Binomial Proportions
Source:R/pbetabinomdiff.R
pbetabinomdiff.RdCalculates the cumulative distribution function (CDF) of the difference between two independent Beta-Binomial proportions by exact enumeration. Specifically, computes \(P((Y_t / m_t) - (Y_c / m_c) \le q)\) or \(P((Y_t / m_t) - (Y_c / m_c) > q)\), where \(Y_j \sim \mathrm{BetaBinomial}(m_j, \alpha_j, \beta_j)\) for \(j \in \{t, c\}\).
Arguments
- q
A numeric scalar representing the quantile threshold for the difference in proportions.
- m_t
A positive integer giving the number of future patients in the treatment group.
- m_c
A positive integer giving the number of future patients in the control group.
- alpha_t
A positive numeric scalar giving the first shape parameter of the Beta mixing distribution for the treatment group.
- alpha_c
A positive numeric scalar giving the first shape parameter of the Beta mixing distribution for the control group.
- beta_t
A positive numeric scalar giving the second shape parameter of the Beta mixing distribution for the treatment group.
- beta_c
A positive numeric scalar giving the second shape parameter of the Beta mixing distribution for the control group.
- lower.tail
A logical scalar; if
TRUE(default), the function returns \(P((Y_t / m_t) - (Y_c / m_c) \le q)\), otherwise \(P((Y_t / m_t) - (Y_c / m_c) > q)\).
Details
The probability mass function of \(Y_j \sim \mathrm{BetaBinomial}(m_j, \alpha_j, \beta_j)\) is: $$P(Y_j = k) = \binom{m_j}{k} \frac{B(k + \alpha_j,\; m_j - k + \beta_j)}{B(\alpha_j, \beta_j)}, \quad k = 0, \ldots, m_j$$ where \(B(\cdot, \cdot)\) is the Beta function.
The exact CDF is obtained by enumerating all \((m_t + 1)(m_c + 1)\) outcome combinations and summing the joint probabilities for which the proportion difference satisfies the specified condition. Computation time therefore grows quadratically in \(m_t\) and \(m_c\); for large future sample sizes consider a normal approximation.
The Beta-Binomial distribution arises when the success probability in a Binomial model follows a Beta prior, making it appropriate for posterior predictive calculations in Bayesian binary-endpoint trials.
Examples
# P((Y_t/12) - (Y_c/12) > 0.2) with symmetric Beta(0.5, 0.5) priors
pbetabinomdiff(0.2, 12, 12, 0.5, 0.5, 0.5, 0.5, lower.tail = FALSE)
#> [1] 0.3372581
# P((Y_t/20) - (Y_c/15) > 0.1) with different future sample sizes
pbetabinomdiff(0.1, 20, 15, 1, 1, 1, 1, lower.tail = FALSE)
#> [1] 0.4017857
# P((Y_t/10) - (Y_c/10) > 0) with informative priors
pbetabinomdiff(0, 10, 10, 2, 3, 3, 2, lower.tail = FALSE)
#> [1] 0.2383331
# Lower tail: P((Y_t/15) - (Y_c/15) <= 0.05) with vague priors
pbetabinomdiff(0.05, 15, 15, 1, 1, 1, 1, lower.tail = TRUE)
#> [1] 0.53125