Skip to contents

Computes \(\Pr(\pi_t - \pi_c \le q)\) (or the upper tail \(\Pr(\pi_t - \pi_c > q)\)) for independent \(\pi_t \sim \textrm{Beta}(a_t, b_t)\) and \(\pi_c \sim \textrm{Beta}(a_c, b_c)\). This is the posterior probability used for a single binary endpoint.

Usage

pbetadiff(q, a_t, b_t, a_c, b_c, lower.tail = TRUE)

Arguments

q

Numeric vector of quantiles.

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(\pi_t - \pi_c \le q)\), otherwise \(\Pr(\pi_t - \pi_c > q)\).

Value

A numeric vector of probabilities. All arguments except lower.tail are recycled to a common length; each must have length 1 or the common length.

Details

The upper tail is computed as $$\Pr(\pi_t - \pi_c > q) = \Pr(\pi_c < -q) + \int f_c(x) \Pr(\pi_t > x + q) \, dx,$$ where the integral runs over the values of \(x\) with \(0 \le x + q \le 1\), and the first term is zero for \(q \ge 0\). The integral is evaluated by adaptive Gauss-Kronrod quadrature (the QUADPACK routine used by integrate), with the range split at quantiles of both Beta distributions so that concentrated distributions are integrated accurately. When the density of \(\pi_c\) is unbounded at 0 (\(a_c < 1\)) or at 1 (\(b_c < 1\)), the integral on that side of the median of \(\pi_c\) is evaluated in the variable \(s = x^{a_c}\) or \(s = (1 - x)^{b_c}\), in which the integrand is bounded. The lower tail is computed directly from the same formula with the roles of the two groups exchanged, so both tails are accurate near 0.

Examples

# Posterior probability that the response rate difference exceeds 0.1,
# with Jeffreys priors and 7/12 versus 4/12 responders
pbetadiff(0.1, a_t = 7.5, b_t = 5.5, a_c = 4.5, b_c = 8.5,
          lower.tail = FALSE)
#> [1] 0.7623513