Skip to contents

Computes \(\Pr(Y_t / m_t - Y_c / m_c \le q)\) (or the upper tail \(\Pr(Y_t / m_t - Y_c / m_c > q)\)) for independent \(Y_t \sim \textrm{Beta-binomial}(m_t, a_t, b_t)\) and \(Y_c \sim \textrm{Beta-binomial}(m_c, a_c, b_c)\). This is the posterior predictive probability for the difference in response proportions of a future study with \(m_t\) and \(m_c\) subjects.

Usage

pbetabinomdiff(q, m_t, a_t, b_t, m_c, a_c, b_c, lower.tail = TRUE)

Arguments

q

Numeric vector of quantiles.

m_t, m_c

Numbers of future subjects in the treatment and control groups (whole numbers of at least 1).

a_t, b_t

Positive shape parameters of the treatment group.

a_c, b_c

Positive shape parameters of the control group.

lower.tail

Logical; if TRUE (default), probabilities are \(\Pr(Y_t / m_t - Y_c / m_c \le q)\), otherwise \(\Pr(Y_t / m_t - Y_c / m_c > q)\).

Value

A numeric vector of probabilities. The arguments q, a_t, b_t, a_c and b_c are recycled to a common length; each must have length 1 or the common length.

Details

The probability is an exact finite sum. The probability mass functions are computed on the log scale, so large values of \(m_t\) and \(m_c\) do not cause overflow. Each difference is compared with q after a single division of the exact integer numerator \(m_c Y_t - m_t Y_c\) by \(m_t m_c\), so differences that are mathematically equal to a decimal q are classified correctly (they belong to the lower tail).

Examples

# Predictive probability that the future difference exceeds 0, with
# Jeffreys priors, 7/12 versus 4/12 responders and 20 future subjects per
# group
pbetabinomdiff(0, m_t = 20, a_t = 7.5, b_t = 5.5, m_c = 20, a_c = 4.5,
               b_c = 8.5, lower.tail = FALSE)
#> [1] 0.8068606