| pbetadiff | R Documentation |
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\}.
pbetadiff(q, alpha_t, alpha_c, beta_t, beta_c, lower.tail = TRUE)
q |
A numeric scalar in |
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 |
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.
A numeric scalar in [0, 1].
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.