pbetadiff: Cumulative Distribution Function of the Difference Between...

View source: R/pbetadiff.R

pbetadiffR Documentation

Cumulative Distribution Function of the Difference Between Two Independent Beta Variables

Description

Calculates the cumulative distribution function (CDF) of the difference between two independent Beta-distributed random variables. Specifically, computes P(\pi_t - \pi_c \le q) or P(\pi_t - \pi_c > q), where \pi_j \sim \mathrm{Beta}(\alpha_j, \beta_j) for j \in \{t, c\}.

Usage

pbetadiff(q, alpha_t, alpha_c, beta_t, beta_c, lower.tail = TRUE)

Arguments

q

A numeric scalar in [-1, 1] representing the quantile threshold for the difference in proportions.

alpha_t

A positive numeric scalar giving the first shape parameter of the Beta distribution for the treatment group.

alpha_c

A positive numeric scalar giving the first shape parameter of the Beta distribution for the control group.

beta_t

A positive numeric scalar giving the second shape parameter of the Beta distribution for the treatment group.

beta_c

A positive numeric scalar giving the second shape parameter of the Beta distribution for the control group.

lower.tail

A logical scalar; if TRUE (default), the function returns P(\pi_t - \pi_c \le q), otherwise P(\pi_t - \pi_c > q).

Details

The upper-tail probability is obtained via the convolution formula:

P(\pi_t - \pi_c > q) = \int_0^1 F_{\mathrm{Beta}(\alpha_c, \beta_c)}(x - q)\, f_{\mathrm{Beta}(\alpha_t, \beta_t)}(x)\, dx

where f_{\mathrm{Beta}(\alpha_t, \beta_t)} is the density of \pi_t and F_{\mathrm{Beta}(\alpha_c, \beta_c)} is the CDF of \pi_c. Boundary cases are handled automatically by pbeta (0 for x - q \le 0, 1 for x - q \ge 1), so integrating over [0, 1] is safe.

This single-integral convolution replaces an equivalent double-integral formulation based on Appell's F1 hypergeometric function, yielding the same result with lower computational cost because both pbeta and dbeta are implemented in compiled C code.

Value

A numeric scalar in [0, 1].

Examples

# P(pi_t - pi_c > 0.2) with symmetric Beta(0.5, 0.5) priors
pbetadiff(0.2, 0.5, 0.5, 0.5, 0.5, lower.tail = FALSE)

# P(pi_t - pi_c > -0.1) with informative priors
pbetadiff(-0.1, 2, 1, 3, 4, lower.tail = FALSE)

# P(pi_t - pi_c > 0) with equal priors -- should be approximately 0.5
pbetadiff(0, 1, 1, 1, 1, lower.tail = FALSE)

# Lower tail: P(pi_t - pi_c <= 0.1) with symmetric priors
pbetadiff(0.1, 2, 2, 2, 2, lower.tail = TRUE)


BayesianQDM documentation built on April 22, 2026, 1:09 a.m.