Package {brar}


Version: 0.1.1
Date: 2026-09-25
Maintainer: Samuel Pawel <samuel.pawel@uzh.ch>
Title: Null Hypothesis Bayesian Response-Adaptive Randomization
Description: Implements Bayesian response-adaptive randomization methods based on Bayesian hypothesis testing for multi-arm settings (Pawel and Held, 2025, <doi:10.48550/arXiv.2510.01734>).
License: GPL-3
Encoding: UTF-8
Imports: mvtnorm
Suggests: roxygen2, tinytest
NeedsCompilation: no
URL: https://github.com/SamCH93/brar
BugReports: https://github.com/SamCH93/brar/issues
Config/roxygen2/version: 8.0.0
Packaged: 2026-09-25 07:59:21 UTC; sam
Author: Samuel Pawel ORCID iD [aut, cre]
Repository: CRAN
Date/Publication: 2026-09-25 08:40:02 UTC

Bayesian response-adaptive randomization for binomial outcomes

Description

This function computes Bayes factors, posterior probabilities, and response-adaptive randomization probabilities for binomial outcomes.

Usage

brar_binomial(
  y,
  n,
  a0 = 1,
  b0 = 1,
  a = rep(1, length(y)),
  b = rep(1, length(y)),
  pH0 = 0.5,
  ...
)

Arguments

y

Vector with the number of successes in each group. The first element corresponds to the control group, and the remaining elements correspond to the treatment groups

n

Vector with the number of observations in each group. The first element corresponds to the control group, and the remaining elements correspond to the treatment groups

a0

First shape parameter of the beta prior for the common success probability under the null hypothesis. Can be interpreted as prior number of successes. Defaults to 1

b0

Second shape parameter of the beta prior for the common success probability under the null hypothesis. Can be interpreted as prior number of failures. Defaults to 1

a

Vector of first shape parameters of the beta priors for the success probabilities under the alternative hypothesis. Can be interpreted as prior numbers of successes. The first element corresponds to the control group, and the remaining elements correspond to the treatment groups. Defaults to rep(1, length(y))

b

Vector of second shape parameters of the beta priors for the success probabilities under the alternative hypothesis. Can be interpreted as prior numbers of failures. The first element corresponds to the control group, and the remaining elements correspond to the treatment groups. Defaults to rep(1, length(y))

pH0

Prior probability of the null hypothesis (i.e., a common probability in the control and all treatment groups). Defaults to 0.5. Set to 0 to obtain Thompson sampling and to 1 to obtain equal randomization

...

Other arguments passed to stats::integrate

Value

An object of class "brar". This is a list with the following elements:

data

The input data.

prior

Prior probabilities of the null hypothesis and of each group being superior to all other groups.

BF_ij

Matrix of Bayes factors. Entry (i, j) is the Bayes factor of hypothesis i against hypothesis j.

posterior

Posterior probabilities of the null hypothesis and of each group being superior to all other groups.

prand

Response-adaptive randomization probabilities

Author(s)

Samuel Pawel

Examples

## 1 control and 1 treatment group
y <- c(15, 12)
n <- c(20, 15)
brar_binomial(y = y, n = n, pH0 = 0.5)

## 1 control and 5 treatment groups
y <- c(10, 10, 10, 10, 10, 10)
n <- c(15, 15, 20, 17, 13, 25)
brar_binomial(y = y, n = n, pH0 = 0.5)


Bayesian response-adaptive randomization for approximately normal effect estimates

Description

This function computes Bayes factors, posterior probabilities, and response-adaptive randomization probabilities for data summarized by approximately normal effect estimates.

Usage

brar_normal(estimate, sigma, pm = rep(0, length(estimate)), psigma, pH0 = 0.5)

Arguments

estimate

Vector of effect estimates (e.g., a vector of mean differences or log odds/hazard/rate ratios). Each estimate quantifies the effect of a treatment relative to control

sigma

Covariance matrix of the effect estimate vector. If there is only one effect estimate, this is the squared standard error of the estimate

pm

Mean vector of the normal prior assigned to the effects under the alternative hypothesis. Defaults to rep(0, length(estimate))

psigma

Covariance matrix of the normal prior assigned to the effects under the alternative hypothesis. If there is only one effect estimate, this is the prior variance

pH0

Prior probability of the point null hypothesis (i.e., all treatment effects equal to 0). Defaults to 0.5. Set to 0 to obtain Thompson sampling and to 1 to obtain equal randomization

Value

An object of class "brar". This is a list with the following elements:

data

The input data.

prior

Prior probabilities of the null hypothesis and of each group being superior to all other groups.

BF_ij

Matrix of Bayes factors. Entry (i, j) is the Bayes factor of hypothesis i against hypothesis j.

posterior

Posterior probabilities of the null hypothesis and of each group being superior to all other groups.

prand

Response-adaptive randomization probabilities

Author(s)

Samuel Pawel

Examples

## simulate normal data from a control group and four treatment groups
set.seed(42)
n <- 10
muc <- 0
datc <- data.frame(y = rnorm(n, muc), group = "Control")
mu <- c(1, -0.5, 0, 0.25)
K <- length(mu)
datt <- do.call("rbind", lapply(seq(1, K), function(k) {
  data.frame(y = rnorm(n, mu[k]), group = paste("Treatment", k))
}))
dat <- rbind(datc, datt)
fit <- lm(y ~ group, data = dat)
estimate <- fit$coef[-1]
sigma <- vcov(fit)[-1,-1]
pm <- rep(0, K)

## prior correlation 0.5 gives the control and each treatment the same prior
## probability of being the best group
rho <- 0.5
psigma <- matrix(rho, nrow = K, ncol = K)
diag(psigma) <- 1
brar_normal(estimate = estimate, sigma = sigma, pm = pm, psigma = psigma,
            pH0 = 0.5)

## brar for the first treatment group only
est <- summary(fit)$coefficients[2,1]
se <- summary(fit)$coefficients[2,2]
brar_normal(est, sigma = se^2, pm = 0, psigma = 1, pH0 = 0.5)