
Bayesian Posterior or Posterior Predictive Probability for a Single Binary Endpoint
Source:R/pbayespostpred1bin.R
pbayespostpred1bin.RdComputes the Bayesian posterior probability or posterior predictive
probability for binary-outcome clinical trials under a beta-binomial
conjugate model. The function supports controlled, uncontrolled, and
external designs, with optional incorporation of external data through
power priors. Vector inputs for y_t and y_c are supported
for efficient batch processing (e.g., across all possible trial outcomes
in pbayesdecisionprob1bin).
Usage
pbayespostpred1bin(
prob = "posterior",
design = "controlled",
theta0,
n_t,
n_c,
y_t,
y_c = NULL,
a_t,
a_c,
b_t,
b_c,
m_t = NULL,
m_c = NULL,
z = NULL,
ne_t = NULL,
ne_c = NULL,
ye_t = NULL,
ye_c = NULL,
alpha0e_t = NULL,
alpha0e_c = NULL,
lower.tail = TRUE
)Arguments
- prob
A character string specifying the probability type. Must be
'posterior'or'predictive'.- design
A character string specifying the trial design. Must be
'controlled','uncontrolled', or'external'.- theta0
A numeric scalar in
(-1, 1)giving the threshold for the treatment effect (difference in response rates).- n_t
A positive integer giving the number of patients in the treatment group in the proof-of-concept (PoC) trial.
- n_c
A positive integer giving the number of patients in the control group in the PoC trial. For
design = 'uncontrolled', this is the hypothetical control sample size (required for consistency with other designs).- y_t
A non-negative integer or integer vector giving the observed number of responders in the treatment group (must satisfy
0 <= y_t <= n_t).- y_c
A non-negative integer or integer vector giving the number of responders in the control group (must satisfy
0 <= y_c <= n_c). Set toNULLfordesign = 'uncontrolled'and usezinstead. When provided as a vector, must have the same length asy_t.- a_t
A positive numeric scalar giving the first shape parameter (alpha) of the prior Beta distribution for the treatment group.
- a_c
A positive numeric scalar giving the first shape parameter (alpha) of the prior Beta distribution for the control group.
- b_t
A positive numeric scalar giving the second shape parameter (beta) of the prior Beta distribution for the treatment group.
- b_c
A positive numeric scalar giving the second shape parameter (beta) of the prior Beta distribution for the control group.
- m_t
A positive integer giving the number of patients in the treatment group for the future trial. Required when
prob = 'predictive'; otherwise set toNULL.- m_c
A positive integer giving the number of patients in the control group for the future trial. Required when
prob = 'predictive'; otherwise set toNULL.- z
A non-negative integer giving the hypothetical number of responders in the control group. Required when
design = 'uncontrolled'; otherwise set toNULL. When used,y_cshould beNULL.- ne_t
A positive integer giving the number of patients in the treatment group of the external data set. Required when
design = 'external'and external treatment data are available; otherwise set toNULL.- ne_c
A positive integer giving the number of patients in the control group of the external data set. Required when
design = 'external'and external control data are available; otherwise set toNULL.- ye_t
A non-negative integer giving the number of responders in the treatment group of the external data set. Required when
design = 'external'; otherwise set toNULL.- ye_c
A non-negative integer giving the number of responders in the control group of the external data set. Required when
design = 'external'; otherwise set toNULL.- alpha0e_t
A numeric scalar in
(0, 1]giving the power prior weight for the external treatment data. Required when external treatment data are used; otherwise set toNULL.- alpha0e_c
A numeric scalar in
(0, 1]giving the power prior weight for the external control data. Required when external control data are used; otherwise set toNULL.- lower.tail
A logical scalar; if
TRUE(default), the function returns \(P(\mathrm{effect} \le \theta_0)\), otherwise \(P(\mathrm{effect} > \theta_0)\).
Value
A numeric scalar or vector in [0, 1]. When y_t and
y_c are vectors of length \(n\), a vector of length
\(n\) is returned.
Details
Posterior shape parameters are computed from the beta-binomial conjugate model:
Prior: \(\pi_j \sim \mathrm{Beta}(a_j, b_j)\).
Posterior: \(\pi_j \mid y_j \sim \mathrm{Beta}(a_j + y_j, b_j + n_j - y_j)\).
For design = 'external', external data are incorporated through
the power prior, which inflates the prior by the weighted external
sufficient statistics:
$$(\alpha_j^*, \beta_j^*) = (a_j + ae_j \cdot ye_j, b_j + ae_j \cdot
(ne_j - ye_j)).$$
For design = 'uncontrolled', the hypothetical control value
z is used in place of y_c, and n_c acts as the
hypothetical control sample size.
The final probability is obtained by calling pbetadiff for
prob = 'posterior' or pbetabinomdiff for
prob = 'predictive', applied element-wise via mapply.
Examples
# Example 1: Controlled design - posterior probability
pbayespostpred1bin(
prob = 'posterior', design = 'controlled', theta0 = 0.15,
n_t = 12, n_c = 15, y_t = 7, y_c = 5,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = NULL, m_c = NULL, z = NULL,
ne_t = NULL, ne_c = NULL, ye_t = NULL, ye_c = NULL,
alpha0e_t = NULL, alpha0e_c = NULL, lower.tail = FALSE
)
#> [1] 0.6860634
# Example 2: Uncontrolled design - posterior probability
pbayespostpred1bin(
prob = 'posterior', design = 'uncontrolled', theta0 = 0.20,
n_t = 20, n_c = 20, y_t = 12, y_c = NULL,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = NULL, m_c = NULL, z = 3,
ne_t = NULL, ne_c = NULL, ye_t = NULL, ye_c = NULL,
alpha0e_t = NULL, alpha0e_c = NULL, lower.tail = FALSE
)
#> [1] 0.952403
# Example 3: External design - posterior probability
pbayespostpred1bin(
prob = 'posterior', design = 'external', theta0 = 0.15,
n_t = 12, n_c = 15, y_t = 7, y_c = 9,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = NULL, m_c = NULL, z = NULL,
ne_t = 12, ne_c = 12, ye_t = 6, ye_c = 6, alpha0e_t = 0.5, alpha0e_c = 0.5,
lower.tail = FALSE
)
#> [1] 0.1399401
# Example 4: Controlled design - posterior predictive probability
pbayespostpred1bin(
prob = 'predictive', design = 'controlled', theta0 = 0.10,
n_t = 12, n_c = 15, y_t = 7, y_c = 5,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = 30, m_c = 30, z = NULL,
ne_t = NULL, ne_c = NULL, ye_t = NULL, ye_c = NULL,
alpha0e_t = NULL, alpha0e_c = NULL, lower.tail = FALSE
)
#> [1] 0.710533
# Example 5: Uncontrolled design - posterior predictive probability
pbayespostpred1bin(
prob = 'predictive', design = 'uncontrolled', theta0 = 0.20,
n_t = 20, n_c = 20, y_t = 12, y_c = NULL,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = 30, m_c = 30, z = 3,
ne_t = NULL, ne_c = NULL, ye_t = NULL, ye_c = NULL,
alpha0e_t = NULL, alpha0e_c = NULL, lower.tail = FALSE
)
#> [1] 0.8874071
# Example 6: External design - posterior predictive probability
pbayespostpred1bin(
prob = 'predictive', design = 'external', theta0 = 0.15,
n_t = 12, n_c = 15, y_t = 7, y_c = 9,
a_t = 0.5, a_c = 0.5, b_t = 0.5, b_c = 0.5,
m_t = 30, m_c = 30, z = NULL,
ne_t = 12, ne_c = 12, ye_t = 6, ye_c = 6, alpha0e_t = 0.5, alpha0e_c = 0.5,
lower.tail = FALSE
)
#> [1] 0.2027863