| Type: | Package |
| Title: | Bayes Factor Design for Two-Arm Binomial Trials |
| Version: | 0.1.2 |
| Date: | 2026-05-06 |
| Description: | Design and analysis of one- and two-stage two-arm binomial clinical phase II trials using Bayes factors. Implements Bayes factors for point-null and directional hypotheses, predictive densities under different hypotheses, and power and sample size calibration. |
| Depends: | R (≥ 4.0.0) |
| Imports: | stats, VGAM, dplyr, parallel, utils, ggplot2, patchwork |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| License: | GPL-3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| VignetteBuilder: | knitr |
| URL: | https://arxiv.org/abs/2511.23144, https://arxiv.org/abs/2603.01715, https://arxiv.org/abs/2502.02914 |
| NeedsCompilation: | no |
| Packaged: | 2026-05-07 13:55:45 UTC; riko |
| Author: | Riko Kelter [aut, cre] |
| Maintainer: | Riko Kelter <rkelter@uni-koeln.de> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-07 15:31:48 UTC |
bfbin2arm: Bayesian Power for Two-Arm Binomial Bayes Factors
Description
Functions for Bayesian power and sample size calculation in two-arm binomial trials using Bayes factors for point-null and directional hypotheses.
Details
The package provides simulation-free and simulation-based methods to calibrate Bayes factor designs in two-arm phase II trials with binary endpoints, including power and type-I-error calculations and visualization tools.
Author(s)
Maintainer: Riko Kelter rkelter@uni-koeln.de
See Also
Useful links:
Bayes factor BF-0: H- vs H0
Description
Bayes factor BF-0: H- vs H0
Usage
BFminus0(BFminus1, BF01)
Arguments
BFminus1 |
Value of BF |
BF01 |
Value of BF |
Value
Numeric scalar, BF_{-0}.
Bayes factor BF-1: H- vs H1
Description
Bayes factor BF-1: H- vs H1
Usage
BFminus1(y1, y2, n1, n2, a_1_a = 1, b_1_a = 1, a_2_a = 1, b_2_a = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, BF_{-1}.
Bayes factor BF+0: H+ vs H0
Description
Bayes factor BF+0: H+ vs H0
Usage
BFplus0(BFplus1, BF01)
Arguments
BFplus1 |
Value of BF |
BF01 |
Value of BF |
Value
Numeric scalar, BF_{+0}.
Bayes factor BF+1: H+ vs H1
Description
Bayes factor BF+1: H+ vs H1
Usage
BFplus1(y1, y2, n1, n2, a_1_a = 1, b_1_a = 1, a_2_a = 1, b_2_a = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, BF_{+1} = posterior odds / prior odds for H+ vs H1.
Bayes factor BF+-: H+ vs H-
Description
Bayes factor BF+-: H+ vs H-
Usage
BFplusMinus(BFplus1, BFminus1)
Arguments
BFplus1 |
Value of BF |
BFminus1 |
Value of BF |
Value
Numeric scalar, BF_{+-}.
Exact frequentist OCs for one two-stage two-arm BF design
Description
Exact frequentist OCs for one two-stage two-arm BF design
Usage
compute_freq_twostage_oc_2arm(
n1_1,
n1_2,
n2_1,
n2_2,
k,
k_f,
test,
p1_power,
p2_power,
p_null_grid = NULL,
a_0_a,
b_0_a,
a_1_a,
b_1_a,
a_2_a,
b_2_a,
a_1_a_Hminus,
b_1_a_Hminus,
a_2_a_Hminus,
b_2_a_Hminus
)
Exact frequentist operating characteristics for a fixed two-stage two-arm BF design
Description
Internal helper. Computes the exact frequentist rejection probability of the two-stage design with futility stopping at interim and efficacy decision at final.
Usage
freq_oc_twostage_twoarm_fixed(
n1_1,
n1_2,
n2_1,
n2_2,
k,
k_f,
test,
p1,
p2,
a_0_a,
b_0_a,
a_1_a,
b_1_a,
a_2_a,
b_2_a,
a_1_a_Hminus,
b_1_a_Hminus,
a_2_a_Hminus,
b_2_a_Hminus
)
Fixed-sample frequentist type-I error supremum over a null grid
Description
Internal helper. For a given fixed-sample design (n1, n2), computes
the supremum of the frequentist type-I error over a grid of null
parameter configurations, using freq_oc_twoarm_fixed().
Usage
freq_t1e_sup_fixed(
n1,
n2,
k,
k_f,
test,
p_null_grid = NULL,
a_0_a,
b_0_a,
a_1_a,
b_1_a,
a_2_a,
b_2_a,
a_1_a_Hminus,
b_1_a_Hminus,
a_2_a_Hminus,
b_2_a_Hminus,
alpha_target = NULL,
tol_excess = 1e-04
)
Two-stage frequentist type-I error supremum over a null grid
Description
Internal helper. For a given two-stage design (n1_1, n1_2, n2_1, n2_2), computes the supremum of the two-stage frequentist type-I error over a grid of null parameter configurations, using freq_oc_twostage_twoarm_fixed().
Usage
freq_t1e_twostage_twoarm_sup(
n1_1,
n1_2,
n2_1,
n2_2,
k,
k_f,
test,
p_null_grid = NULL,
a_0_a,
b_0_a,
a_1_a,
b_1_a,
a_2_a,
b_2_a,
a_1_a_Hminus,
b_1_a_Hminus,
a_2_a_Hminus,
b_2_a_Hminus,
alpha_target = NULL,
tol_excess = 1e-04
)
Sample size calibration for two-arm binomial Bayes factor designs
Description
Searches over a grid of total sample sizes n to find the smallest n such that Bayesian power, Bayesian type-I error, and probability of compelling evidence under H0 meet specified design criteria. Optionally, frequentist type-I error and power constraints are also evaluated. Unequal fixed randomisation between the two arms is allowed via alloc1 and alloc2.
Usage
ntwoarmbinbf01(
k = 1/3,
k_f = 1/3,
power = 0.8,
alpha = 0.05,
pce_H0 = 0.9,
test = c("BF01", "BF+0", "BF-0", "BF+-"),
nrange = c(10, 150),
n_step = 1,
progress = TRUE,
compute_freq_t1e = FALSE,
p1_grid = seq(0.01, 0.99, 0.02),
p2_grid = seq(0.01, 0.99, 0.02),
p1_power = NULL,
p2_power = NULL,
a_0_d = 1,
b_0_d = 1,
a_0_a = 1,
b_0_a = 1,
a_1_d = 1,
b_1_d = 1,
a_2_d = 1,
b_2_d = 1,
a_1_a = 1,
b_1_a = 1,
a_2_a = 1,
b_2_a = 1,
output = c("plot", "numeric"),
a_1_d_Hminus = 1,
b_1_d_Hminus = 1,
a_2_d_Hminus = 1,
b_2_d_Hminus = 1,
a_1_a_Hminus = 1,
b_1_a_Hminus = 1,
a_2_a_Hminus = 1,
b_2_a_Hminus = 1,
alloc1 = 0.5,
alloc2 = 0.5
)
Arguments
k |
Evidence threshold for rejecting the null (inverted BF). |
k_f |
Evidence threshold for "compelling evidence" in favour of the null. |
power |
Target Bayesian power. |
alpha |
Target Bayesian type-I error. |
pce_H0 |
Target probability of compelling evidence under |
test |
Character string, one of |
nrange |
Integer vector of length 2 giving the search range for total n. |
n_step |
Step size for n. |
progress |
Logical; if |
compute_freq_t1e |
Logical; if |
p1_grid, p2_grid |
Grids of true proportions for frequentist T1E. |
p1_power, p2_power |
Optional true proportions for frequentist power. |
a_0_d, b_0_d, a_0_a, b_0_a |
Shape parameters for design and analysis priors
under |
a_1_d, b_1_d, a_2_d, b_2_d |
Shape parameters for design priors under
|
a_1_a, b_1_a, a_2_a, b_2_a |
Shape parameters for analysis priors under
|
output |
|
a_1_d_Hminus, b_1_d_Hminus, a_2_d_Hminus, b_2_d_Hminus |
Optional design
priors under |
a_1_a_Hminus, b_1_a_Hminus, a_2_a_Hminus, b_2_a_Hminus |
Shape parameters for analysis priors under H-. |
alloc1, alloc2 |
Fixed randomisation probabilities for arm 1 and arm 2; must be positive and sum to 1. Defaults are 0.5 and 0.5. |
Value
If output = "plot", returns invisibly a list with recommended
sample sizes and a ggplot object printed to the device. If
output = "numeric", returns a list with recommended n and summary.
Examples
# Standard calibration with equal allocation: power 80%, type-I 5%, CE(H0) 80%
ntwoarmbinbf01(power = 0.8, alpha = 0.05, pce_H0 = 0.8, output = "numeric")
# 1:2 allocation (control:treatment) via alloc1 = 1/3, alloc2 = 2/3
ntwoarmbinbf01(power = 0.8, alpha = 0.05, pce_H0 = 0.8,
alloc1 = 1/3, alloc2 = 2/3, output = "numeric")
# BF+0 directional test with plot
ntwoarmbinbf01(power = 0.8, alpha = 0.05, pce_H0 = 0.9,
test = "BF+0", output = "plot")
Optimal two-stage two-arm Bayes-factor design for binary endpoints
Description
Computes an optimal two-stage two-arm Bayes-factor design for binary endpoints, minimizing the expected sample size under the null hypothesis while correcting the operating characteristics for the possibility of early stopping for futility.
Usage
optimal_twostage_2arm_bf(
alpha = 0.05,
beta = 0.2,
k = 1/3,
k_f = 3,
n1_min = c(5, 5),
n2_max = c(50, 50),
alloc1 = 0.5,
alloc2 = 0.5,
power_cushion = 0,
pceH0 = NULL,
interim_fraction = c(0, 1),
grid_step = 1L,
coarse_step = 10L,
progress = TRUE,
max_iter = 10000L,
ncores = getOption("bfbin2arm.ncores", 1L),
compute_freq_oc = NULL,
calibration_mode = c("Bayesian", "frequentist", "hybrid"),
calibration_EN = NULL,
p1_EN_H0 = NULL,
p2_EN_H0 = NULL,
alpha_freq = alpha,
beta_freq = beta,
p1_power = NULL,
p2_power = NULL,
p_null_grid = NULL,
test = "BF01",
a_0_d = 1,
b_0_d = 1,
a_0_a = 1,
b_0_a = 1,
a_1_d = 1,
b_1_d = 1,
a_2_d = 1,
b_2_d = 1,
a_1_a = 1,
b_1_a = 1,
a_2_a = 1,
b_2_a = 1,
a_1_d_Hminus = 1,
b_1_d_Hminus = 1,
a_2_d_Hminus = 1,
b_2_d_Hminus = 1,
a_1_a_Hminus = 1,
b_1_a_Hminus = 1,
a_2_a_Hminus = 1,
b_2_a_Hminus = 1
)
Arguments
alpha |
Numeric scalar, Bayesian type-I-error target. |
beta |
Numeric scalar, 1 minus the minimal Bayesian power target. |
k |
Numeric scalar, efficacy threshold; evidence against the null
hypothesis is declared when the corresponding Bayes factor is smaller
than |
k_f |
Numeric scalar, futility threshold; compelling evidence for the
null hypothesis is declared when the corresponding Bayes factor is at
least |
n1_min |
Numeric vector of length 2, minimum interim sample sizes for arms 1 and 2. |
n2_max |
Numeric vector of length 2, maximum final sample sizes for arms 1 and 2. |
alloc1, alloc2 |
Positive numbers, allocation probabilities to arms 1 and 2. |
power_cushion |
Numeric scalar, optional extra power cushion used in the fixed-sample search of step 1. |
pceH0 |
Optional numeric scalar in |
interim_fraction |
Numeric vector of length 2 giving lower and upper bounds for the interim sample size in each arm as a fraction of the fixed sample size. |
grid_step |
Positive integer giving the spacing of the interim design grid. |
coarse_step |
Positive integer giving the spacing of the coarse fixed-sample search grid in step 1. |
progress |
Logical; if |
max_iter |
Integer, maximum number of total fixed-sample sizes searched in step 1. |
ncores |
Integer; number of parallel worker processes to use in the
calibration. Defaults to |
compute_freq_oc |
Logical or |
calibration_mode |
Character string specifying the calibration mode.
Must be one of |
calibration_EN |
Character string or |
p1_EN_H0, p2_EN_H0 |
Numeric scalars specifying the null response
probabilities in control and treatment arm used when
|
alpha_freq |
Numeric scalar, frequentist type-I error target. |
beta_freq |
Numeric scalar, 1 minus the frequentist power target. |
p1_power, p2_power |
Numeric scalars specifying the success probabilities in control and treatment arm used for the frequentist power calculation. |
p_null_grid |
Optional numeric vector giving the grid of null response
probabilities used for frequentist type-I-error maximization. If
|
test |
Character string, one of |
a_0_d, b_0_d, a_0_a, b_0_a |
Shape parameters for design and analysis priors
under |
a_1_d, b_1_d, a_2_d, b_2_d |
Shape parameters for design priors under
|
a_1_a, b_1_a, a_2_a, b_2_a |
Shape parameters for analysis priors under
|
a_1_d_Hminus, b_1_d_Hminus, a_2_d_Hminus, b_2_d_Hminus |
Optional design
priors under |
a_1_a_Hminus, b_1_a_Hminus |
Shape parameters of the analysis prior under the directional null hypothesis H0- for arm 1. |
a_2_a_Hminus, b_2_a_Hminus |
Shape parameters of the analysis prior under the directional null hypothesis H0- for arm 2. |
Value
A list with the following components:
design |
Four-element integer vector containing the selected two-stage design: interim sample sizes in arms 1 and 2 followed by final sample sizes in arms 1 and 2. |
naive_oc |
Named list of uncorrected fixed-sample operating characteristics and fixed-sample sizes found in step 1. |
occ |
Named numeric vector of corrected Bayesian operating characteristics for the selected two-stage design. |
priors |
List storing design hyperparameters and search settings. |
freq_occ |
Named numeric vector with fixed-sample and two-stage
frequentist operating characteristics for the final design when frequentist
calibration or reporting is active; otherwise |
conv |
Character string describing the search outcome. Typical values
include |
Examples
## Fast Bayesian example with small search space
res <- optimal_twostage_2arm_bf(
alpha = 0.10,
beta = 0.20,
k = 1 / 3,
k_f = 3,
n1_min = c(3, 3),
n2_max = c(12, 12),
alloc1 = 0.5,
alloc2 = 0.5,
power_cushion = 0,
pceH0 = NULL,
interim_fraction = c(0.25, 0.75),
grid_step = 2L,
coarse_step = 4L,
progress = FALSE,
max_iter = 24L,
calibration_mode = "Bayesian",
test = "BF01",
a_0_d = 1, b_0_d = 1,
a_0_a = 1, b_0_a = 1,
a_1_d = 1, b_1_d = 1,
a_2_d = 1, b_2_d = 1,
a_1_a = 1, b_1_a = 1,
a_2_a = 1, b_2_a = 1
)
res$design
res$occ
res2 <- optimal_twostage_2arm_bf(
alpha = 0.05,
beta = 0.20,
k = 1 / 3,
k_f = 3,
n1_min = c(5, 5),
n2_max = c(20, 20),
alloc1 = 0.5,
alloc2 = 0.5,
power_cushion = 0.02,
pceH0 = 0.50,
interim_fraction = c(0.25, 0.75),
grid_step = 1L,
coarse_step = 4L,
progress = FALSE,
max_iter = 40L,
calibration_mode = "Bayesian",
test = "BF+0",
a_0_d = 1, b_0_d = 1,
a_0_a = 1, b_0_a = 1,
a_1_d = 1, b_1_d = 2,
a_2_d = 2, b_2_d = 1,
a_1_a = 1, b_1_a = 1,
a_2_a = 1, b_2_a = 1,
a_1_d_Hminus = 1, b_1_d_Hminus = 1,
a_2_d_Hminus = 1, b_2_d_Hminus = 1,
a_1_a_Hminus = 1, b_1_a_Hminus = 1,
a_2_a_Hminus = 1, b_2_a_Hminus = 1
)
res2$design
res2$occ
Plot an optimal two-stage two-arm Bayes factor design
Description
Given the result from optimal_twostage_2arm_bf(), this function
produces a six-panel base R plot showing the design schematic, operating
characteristics, and the design and analysis priors under H_0 and
H_1.
Usage
plot_twostage_2arm_bf(
res,
main = "Optimal two-stage two-arm Bayes factor design"
)
Arguments
res |
A list returned by |
main |
Character string with the main title of the plot. |
Value
Invisibly returns NULL; called for its side effect of
producing a plot.
Examples
res <- optimal_twostage_2arm_bf(
alpha = 0.10, beta = 0.20, k = 1/3, k_f = 3,
n1_min = c(3, 3), n2_max = c(8, 8),
alloc1 = 0.5, alloc2 = 0.5,
power_cushion = 0,
interim_fraction = c(0.5, 0.5),
grid_step = 1,
progress = FALSE,
max_iter = 16,
test = "BF01",
a_0_d = 1, b_0_d = 1,
a_0_a = 1, b_0_a = 1,
a_1_d = 1, b_1_d = 1,
a_2_d = 1, b_2_d = 1,
a_1_a = 1, b_1_a = 1,
a_2_a = 1, b_2_a = 1
)
if (is.numeric(res$design) && length(res$design) == 4 && !anyNA(res$design)) {
plot_twostage_2arm_bf(res)
}
Posterior probability P(p2 <= p1 | data)
Description
Posterior probability P(p2 <= p1 | data)
Usage
postProbHminus(y1, y2, n1, n2, a_1_a = 1, b_1_a = 1, a_2_a = 1, b_2_a = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, posterior probability P(p_2 <= p_1 | y_1, y_2).
Posterior probability P(p2 > p1 | data) under independent Beta priors
Description
Uses Beta posteriors induced by the analysis priors to compute
P(p_2 > p_1 \mid y_1, y_2).
Usage
postProbHplus(y1, y2, n1, n2, a_1_a = 1, b_1_a = 1, a_2_a = 1, b_2_a = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, posterior probability P(p_2 > p_1 | y_1, y_2).
Bayesian power, type-I error, and PCE(H0) for two-arm binomial Bayes factors
Description
Computes Bayesian power, Bayesian type-I error, and the probability of compelling evidence under H_0 (or H_- for BF+-), for a given sample size and Bayes factor test. Optionally, frequentist type-I error and frequentist power are computed by summing over the rejection region.
Usage
powertwoarmbinbf01(
n1,
n2,
k = 1/3,
k_f = 1/3,
test = c("BF01", "BF+0", "BF-0", "BF+-"),
a_0_d = 1,
b_0_d = 1,
a_0_a = 1,
b_0_a = 1,
a_1_d = 1,
b_1_d = 1,
a_2_d = 1,
b_2_d = 1,
a_1_a = 1,
b_1_a = 1,
a_2_a = 1,
b_2_a = 1,
output = c("numeric", "predDensmatrix", "t1ematrix", "ceH0matrix", "frequentist_t1e"),
a_1_d_Hminus = 1,
b_1_d_Hminus = 1,
a_2_d_Hminus = 1,
b_2_d_Hminus = 1,
compute_freq_t1e = FALSE,
p1_grid = seq(0.01, 0.99, 0.02),
p2_grid = seq(0.01, 0.99, 0.02),
p1_power = NULL,
p2_power = NULL,
a_1_a_Hminus = 1,
b_1_a_Hminus = 1,
a_2_a_Hminus = 1,
b_2_a_Hminus = 1
)
Arguments
n1, n2 |
Sample sizes in arms 1 and 2. |
k |
Evidence threshold for rejecting the null (inverted BF). |
k_f |
Evidence threshold for "compelling evidence" in favour of the null. |
test |
Character string, one of |
a_0_d, b_0_d, a_0_a, b_0_a |
Shape parameters for design and analysis priors
under |
a_1_d, b_1_d, a_2_d, b_2_d |
Shape parameters for design priors under
|
a_1_a, b_1_a, a_2_a, b_2_a |
Shape parameters for analysis priors under
|
output |
One of |
a_1_d_Hminus, b_1_d_Hminus, a_2_d_Hminus, b_2_d_Hminus |
Optional design
priors under |
compute_freq_t1e |
Logical; if |
p1_grid, p2_grid |
Grids of true proportions for frequentist T1E. |
p1_power, p2_power |
Optional true proportions for frequentist power. |
a_1_a_Hminus, b_1_a_Hminus, a_2_a_Hminus, b_2_a_Hminus |
Shape parameters
for analysis priors under |
Value
Depending on output, either a named numeric vector with
components Power, Type1_Error, CE_H0 (and optionally
frequentist metrics) or matrices of predictive densities.
Examples
# Basic Bayesian power for BF01 test
powertwoarmbinbf01(n1 = 30, n2 = 30, k = 1/3, test = "BF01")
# Directional test BF+0 with frequentist type-I error
powertwoarmbinbf01(n1 = 40, n2 = 40, k = 1/3, k_f = 3,
test = "BF+0", compute_freq_t1e = TRUE)
# Predictive density matrices (advanced)
powertwoarmbinbf01(n1 = 25, n2 = 25, output = "predDensmatrix")
Predictive density under H0: p1 = p2 = p
Description
Beta-binomial predictive density for data (y1,y2) under H0.
Usage
predictiveDensityH0(y1, y2, n1, n2, a_0_d = 1, b_0_d = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_0_d, b_0_d |
Design-prior parameters for common p under H0. |
Value
Numeric scalar, predictive density.
Predictive density under H1: p1 != p2
Description
Product of two independent Beta-binomial predictive densities.
Usage
predictiveDensityH1(y1, y2, n1, n2, a_1_d = 1, b_1_d = 1, a_2_d = 1, b_2_d = 1)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_d, b_1_d |
Design-prior parameters for p1. |
a_2_d, b_2_d |
Design-prior parameters for p2. |
Value
Numeric scalar, predictive density.
Predictive density under H-: p2 <= p1 (truncated prior)
Description
Predictive density under H-: p2 <= p1 (truncated prior)
Usage
predictiveDensityHminus_trunc(
y1,
y2,
n1,
n2,
a_1_d = 1,
b_1_d = 1,
a_2_d = 1,
b_2_d = 1
)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_d, b_1_d |
Design-prior parameters for p1. |
a_2_d, b_2_d |
Design-prior parameters for p2. |
Value
Numeric scalar, predictive density under H-.
Predictive density under H+: p2 > p1 (truncated prior)
Description
Predictive density under H+: p2 > p1 (truncated prior)
Usage
predictiveDensityHplus_trunc(
y1,
y2,
n1,
n2,
a_1_d = 1,
b_1_d = 1,
a_2_d = 1,
b_2_d = 1
)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_1_d, b_1_d |
Design-prior parameters for p1. |
a_2_d, b_2_d |
Design-prior parameters for p2. |
Value
Numeric scalar, predictive density under H+.
Prior probability P(p2 <= p1) under independent Beta priors
Description
Prior probability P(p2 <= p1) under independent Beta priors
Usage
priorProbHminus(a_1_a, b_1_a, a_2_a, b_2_a)
Arguments
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, prior probability P(p2 <= p1).
Prior probability P(p2 > p1) under independent Beta priors
Description
Prior probability P(p2 > p1) under independent Beta priors
Usage
priorProbHplus(a_1_a, b_1_a, a_2_a, b_2_a)
Arguments
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, prior probability P(p2 > p1).
Two-arm binomial Bayes factor BF01
Description
Computes the Bayes factor BF_{01} comparing the point-null
H_0: p_1 = p_2 to the alternative H_1: p_1 \neq p_2
in a two-arm binomial setting with Beta priors.
Usage
twoarmbinbf01(
y1,
y2,
n1,
n2,
a_0_a = 1,
b_0_a = 1,
a_1_a = 1,
b_1_a = 1,
a_2_a = 1,
b_2_a = 1
)
Arguments
y1 |
Number of successes in arm 1 (control). |
y2 |
Number of successes in arm 2 (treatment). |
n1 |
Sample size in arm 1. |
n2 |
Sample size in arm 2. |
a_0_a, b_0_a |
Shape parameters of the Beta prior for the common- |
a_1_a, b_1_a |
Shape parameters of the Beta prior for |
a_2_a, b_2_a |
Shape parameters of the Beta prior for |
Value
Numeric scalar, the Bayes factor BF_{01}.
Examples
twoarmbinbf01(10, 20, 30, 30)
Bayes factor BF+0 for the directional alternative vs point-null
Description
Computes the Bayes factor BF_{+0} comparing the directional
alternative hypothesis H_+ (p_2 > p_1) against the point-null
H_0 (p_1 = p_2).
Usage
twoarmbinbf_plus0_direct(
y1,
y2,
n1,
n2,
a_0_a = 1,
b_0_a = 1,
a_1_a = 1,
b_1_a = 1,
a_2_a = 1,
b_2_a = 1
)
Arguments
y1, y2 |
Integer counts of successes in arms 1 and 2. |
n1, n2 |
Integer sample sizes in arms 1 and 2. |
a_0_a, b_0_a |
Shape parameters of the analysis prior for the common
response probability under |
a_1_a, b_1_a |
Shape parameters of the analysis prior for the
response probability in arm 1 under |
a_2_a, b_2_a |
Shape parameters of the analysis prior for the
response probability in arm 2 under |
Details
Both marginal likelihoods are formed using the analysis priors, which represent inferential beliefs at the time the data are evaluated. The design priors are used only for computing Bayesian operating characteristics (predictive power / type-I error) and play no role here.
Value
Numeric scalar; the Bayes factor
BF_{+0} = m_+(y_1, y_2) / m_0(y_1, y_2).