nbinbf01: Sample size determination for binomial Bayes factor

nbinbf01R Documentation

Sample size determination for binomial Bayes factor

Description

This function computes the required sample size to obtain a binomial Bayes factor (binbf01) more extreme than a threshold k with a specified target power.

Usage

nbinbf01(
  k,
  power,
  p0 = 0.5,
  type = c("point", "direction"),
  a = 1,
  b = 1,
  dp = NA,
  da = a,
  db = b,
  dl = 0,
  du = 1,
  lower.tail = TRUE,
  nrange = c(1, 10^4),
  ...
)

Arguments

k

Bayes factor threshold

power

Target power

p0

Tested binomial proportion. Defaults to 0.5

type

Type of test. Can be "point" or "directional". Defaults to "point"

a

Number of successes parameter of the beta analysis prior distribution. Defaults to 1

b

Number of failures parameter of the beta analysis prior distribution. Defaults to 1

dp

Fixed binomial proportion assumed for the power calculation. Set to NA to use a truncated beta design prior instead (specified via the da, db, dl, and du arguments). Defaults to NA

da

Number of successes parameter of the truncated beta design prior distribution. Is only taken into account if dp = NA. Defaults to the same value a as specified for the analysis prior

db

Number of failures parameter of the truncated beta design prior distribution. Is only taken into account if dp = NA. Defaults to the same value b as specified for the analysis prior

dl

Lower truncation limit of of the truncated beta design prior distribution. Is only taken into account if dp = NA. Defaults to 0

du

Upper truncation limit of of the truncated beta design prior distribution. Is only taken into account if dp = NA. Defaults to 1

lower.tail

Logical indicating whether Pr(\mathrm{BF}_{01} \leq k) (TRUE) or Pr(\mathrm{BF}_{01} > k) (FALSE) should be computed. Defaults to TRUE

nrange

Sample size search range over which numerical search is performed. Defaults to c(1, 10^4)

...

Other arguments passed to stats::uniroot

Value

The required sample size to achieve the specified power

Author(s)

Samuel Pawel

See Also

pbinbf01, binbf01

Examples

## sample size parameters
pow <- 0.9
p0 <- 3/4
a <- 1
b <- 1
k <- 1/10

## Not run: 
## sample sizes for directional testing
(nH1 <- nbinbf01(k = k, power = pow, p0 = p0, type = "direction", a = a,
                 b = b, da = a, db = b, dl = p0, du = 1))
(nH0 <- nbinbf01(k = 1/k, power = pow, p0 = p0, type = "direction", a = a,
                 b = b, da = a, db = b, dl = 0, du = p0, lower.tail = FALSE))
nseq <- seq(1, 1.1*max(c(nH1, nH0)), length.out = 100)
powH1 <- pbinbf01(k = k, n = nseq, p0 = p0, type = "direction", a = a,
                  b = b, da = a, db = b, dl = p0, du = 1)
powH0 <- pbinbf01(k = 1/k, n = nseq, p0 = p0, type = "direction", a = a,
                  b = b, da = a, db = b, dl = 0, du = p0, lower.tail = FALSE)
matplot(nseq, cbind(powH1, powH0), type = "s", xlab = "n", ylab = "Power", lty = 1,
        ylim = c(0, 1), col = c(2, 4), las = 1)
abline(h = pow, lty = 2)
abline(v = c(nH1, nH0), col = c(2, 4), lty = 2)
legend("topleft", legend = c("H1", "H0"), lty = 1, col = c(2, 4))

## sample sizes for point null testing
(nH1 <- nbinbf01(k = k, power = pow, p0 = p0, type = "point", a = a,
                 b = b, da = a, db = b))
(nH0 <- nbinbf01(k = 1/k, power = pow, p0 = p0, type = "point", a = a,
                 b = b, dp = p0, lower.tail = FALSE, nrange = c(1, 10^5)))
nseq <- seq(1, max(c(nH1, nH0)), length.out = 100)
powH1 <- pbinbf01(k = k, n = nseq, p0 = p0, type = "point", a = a,
                  b = b, da = a, db = b, dl = 0, du = 1)
powH0 <- pbinbf01(k = 1/k, n = nseq, p0 = p0, type = "point", a = a,
                  b = b, dp = p0, lower.tail = FALSE)
matplot(nseq, cbind(powH1, powH0), type = "s", xlab = "n", ylab = "Power", lty = 1,
        ylim = c(0, 1), col = c(2, 4), las = 1)
abline(h = pow, lty = 2)
abline(v = c(nH1, nH0), col = c(2, 4), lty = 2)
legend("topleft", legend = c("H1", "H0"), lty = 1, col = c(2, 4))

## End(Not run)

bfpwr documentation built on June 8, 2025, 1:40 p.m.