The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Type: Package
Title: Bayesian Bayes Factor Design for Two-Arm Binomial Trials
Version: 0.1.0
Description: Design and analysis of 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 with optional frequentist type-I error and power.
Depends: R (≥ 4.0.0)
Imports: stats, VGAM, ggplot2, dplyr, patchwork
Suggests: knitr, rmarkdown
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-02-19 15:23:34 UTC; riko
Author: Riko Kelter [aut, cre]
Maintainer: Riko Kelter <rkelter@uni-koeln.de>
Repository: CRAN
Date/Publication: 2026-02-24 19:20:02 UTC

Bayes factor BF-0: H- vs H0

Description

Bayes factor BF-0: H- vs H0

Usage

BFminus0(BFminus1, BF01)

Arguments

BFminus1

Value of BF_{-1}.

BF01

Value of BF_{01}.

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_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 shape parameters for p_1.

a_2_d, b_2_d

Design-prior shape parameters for p_2.

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_{+1}.

BF01

Value of BF_{01}.

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_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 shape parameters for p_1.

a_2_d, b_2_d

Design-prior shape parameters for p_2.

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_{+1}.

BFminus1

Value of BF_{-1}.

Value

Numeric scalar, BF_{+-}.


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 H_0.

test

Character string, one of "BF01", "BF+0", "BF-0", "BF+-".

nrange

Integer vector of length 2 giving the search range for total n.

n_step

Step size for n.

progress

Logical; if TRUE, print progress to the console.

compute_freq_t1e

Logical; if TRUE, compute frequentist type-I error over a grid.

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 H_0.

a_1_d, b_1_d, a_2_d, b_2_d

Shape parameters for design priors under H_1 or H_+.

a_1_a, b_1_a, a_2_a, b_2_a

Shape parameters for analysis priors under H_1 or H_+.

output

"plot" or "numeric".

a_1_d_Hminus, b_1_d_Hminus, a_2_d_Hminus, b_2_d_Hminus

Optional design priors under H_- for directional tests.

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")


Posterior probability P(p2 <= p1 | data)

Description

Posterior probability P(p2 <= p1 | data)

Usage

postProbHminus(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 shape parameters for p_1.

a_2_d, b_2_d

Design-prior shape parameters for p_2.

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

Posterior probability P(p2 > p1 | data) under independent Beta priors

Usage

postProbHplus(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 shape parameters for p_1.

a_2_d, b_2_d

Design-prior shape parameters for p_2.

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
)

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 "BF01", "BF+0", "BF-0", "BF+-".

a_0_d, b_0_d, a_0_a, b_0_a

Shape parameters for design and analysis priors under H_0.

a_1_d, b_1_d, a_2_d, b_2_d

Shape parameters for design priors under H_1 or H_+.

a_1_a, b_1_a, a_2_a, b_2_a

Shape parameters for analysis priors under H_1 or H_+.

output

One of "numeric", "predDensmatrix", "t1ematrix", "ceH0matrix", "frequentist_t1e".

a_1_d_Hminus, b_1_d_Hminus, a_2_d_Hminus, b_2_d_Hminus

Optional design priors under H_- for directional tests.

compute_freq_t1e

Logical; if TRUE, compute frequentist type-I error over a grid.

p1_grid, p2_grid

Grids of true proportions for frequentist T1E.

p1_power, p2_power

Optional true proportions for frequentist power.

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_d, b_1_d, a_2_d, b_2_d)

Arguments

a_1_d, b_1_d

Shape parameters of the Beta prior for p_1.

a_2_d, b_2_d

Shape parameters of the Beta prior for p_2.

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_d, b_1_d, a_2_d, b_2_d)

Arguments

a_1_d, b_1_d

Shape parameters of the Beta prior for p_1.

a_2_d, b_2_d

Shape parameters of the Beta prior for p_2.

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-p under the null model.

a_1_a, b_1_a

Shape parameters of the Beta prior for p_1 under the alternative.

a_2_a, b_2_a

Shape parameters of the Beta prior for p_2 under the alternative.

Value

Numeric scalar, the Bayes factor BF_{01}.

Examples

twoarmbinbf01(10, 20, 30, 30)

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.