Skip to contents

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

a_1_a_Hminus, b_1_a_Hminus, a_2_a_Hminus, b_2_a_Hminus

Shape parameters for analysis priors under \(H_-\) (directional tests).

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")
#>       Power Type1_Error       CE_H0 
#>  0.57232050  0.02071685  0.97928315 
#> attr(,"hypothesis")
#> [1] "H[1]:~p[1] != p[2] ~~ vs ~~ H[0]:~p[1] == p[2]"
#> attr(,"compute_freq_t1e")
#> [1] FALSE

# 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)
#>                   Power             Type1_Error                   CE_H0 
#>              0.66474190              0.02083992              0.70141639 
#> Frequentist_Type1_Error 
#>              0.02831856 
#> attr(,"hypothesis")
#> [1] "H[+]:~p[2] > p[1] ~~ vs ~~ H[0]:~p[1] == p[2]"
#> attr(,"compute_freq_t1e")
#> [1] TRUE

# Predictive density matrices (advanced)
powertwoarmbinbf01(n1 = 25, n2 = 25, output = "predDensmatrix")
#>         [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]  [,10]
#>  [1,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [2,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015
#>  [3,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015
#>  [4,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#>  [5,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#>  [6,] 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#>  [7,] 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#>  [8,] 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#>  [9,] 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [10,] 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [11,] 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [12,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000
#> [13,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000
#> [14,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000
#> [15,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000
#> [16,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000
#> [17,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000
#> [18,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [19,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [20,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [21,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [22,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [23,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [24,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [25,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [26,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>        [,11]  [,12]  [,13]  [,14]  [,15]  [,16]  [,17]  [,18]  [,19]  [,20]
#>  [1,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [2,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [3,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [4,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [5,] 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [6,] 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [7,] 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [8,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [9,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015
#> [10,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015
#> [11,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015
#> [12,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015
#> [13,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [14,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [15,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [16,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [17,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [18,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [19,] 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [20,] 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [21,] 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [22,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000
#> [23,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000 0.0000
#> [24,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000 0.0000 0.0000
#> [25,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0000
#> [26,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>        [,21]  [,22]  [,23]  [,24]  [,25]  [,26]
#>  [1,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [2,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [3,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [4,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [5,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [6,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [7,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [8,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#>  [9,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [10,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [11,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [12,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [13,] 0.0015 0.0015 0.0015 0.0015 0.0015 0.0015
#> [14,] 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015
#> [15,] 0.0000 0.0015 0.0015 0.0015 0.0015 0.0015
#> [16,] 0.0000 0.0000 0.0015 0.0015 0.0015 0.0015
#> [17,] 0.0000 0.0000 0.0000 0.0015 0.0015 0.0015
#> [18,] 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015
#> [19,] 0.0000 0.0000 0.0000 0.0000 0.0015 0.0015
#> [20,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015
#> [21,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0015
#> [22,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [23,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [24,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [25,] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
#> [26,] 0.0015 0.0000 0.0000 0.0000 0.0000 0.0000