Learn R Programming

BayesPower (version 1.0.2)

BFpower.props: Sample Size Determination for the Bayesian test of two proportions

Description

Perform sample size determination or calculate probabilities of compelling and misleading evidence for a Bayesian comparison of two proportions.

Usage

BFpower.props(
  threshold,
  true_rate,
  a0,
  b0,
  a1,
  b1,
  a2,
  b2,
  prior_design_1 = "same",
  a1d,
  b1d,
  dp1,
  prior_design_2 = "same",
  a2d,
  b2d,
  dp2,
  n1 = NULL,
  n2 = NULL,
  type_rate = "positive",
  plot_power = FALSE,
  plot_rel = FALSE
)

Value

An object of class BFpower_2p (a list) containing:

type

Character, always "Two-proportions".

analysis_h0

List of analysis prior parameters under the null, containing a and b.

analysis_h1_theta_1

List of analysis prior parameters for group 1 under the alternative, containing a and b.

analysis_h1_theta_2

List of analysis prior parameters for group 2 under the alternative, containing a and b.

design_h1_theta_1

List of design prior parameters for group 1 under the alternative, containing prior, a, b, and p.

design_h1_theta_2

List of design prior parameters for group 2 under the alternative, containing prior, a, b, and p.

results

Data frame of probabilities of compelling and misleading evidence.

grid

Grid used for computation.

threshold

Threshold of compelling evidence.

mode_bf

Character string specifying the mode (sample size determination or power calculation).

plot_power

Logical; whether the power curve is plotted.

plot_rel

Logical; whether the relationship between the Bayes factor and observed proportion differences is plotted.

Arguments

threshold

Numeric scalar. Threshold of compelling evidence.

true_rate

Numeric scalar. Targeted true positive rate (if positive = "positive") or true negative rate (if positive = "negative").

a0

Numeric scalar. Alpha parameter of the Beta prior under the null hypothesis.

b0

Numeric scalar. Beta parameter of the Beta prior under the null hypothesis.

a1

Numeric scalar. Alpha parameter of the Beta analysis prior for group 1 under the alternative hypothesis.

b1

Numeric scalar. Beta parameter of the Beta analysis prior for group 1 under the alternative hypothesis.

a2

Numeric scalar. Alpha parameter of the Beta analysis prior for group 2 under the alternative hypothesis.

b2

Numeric scalar. Beta parameter of the Beta analysis prior for group 2 under the alternative hypothesis.

prior_design_1

Character. The design prior of group 1: "beta", "Point", or "same" (if "same", the design prior is identical to the analysis prior).

a1d

Numeric scalar. Alpha parameter of the design prior for group 1 (used if model1 = "beta").

b1d

Numeric scalar. Beta parameter of the design prior for group 1 (used if model1 = "beta").

dp1

Numeric scalar. True proportion for group 1 in the design prior (used if model1 = "Point").

prior_design_2

Character. The design prior of group 2: "beta", "Point", or "same" (if "same", the design prior is identical to the analysis prior).

a2d

Numeric scalar. Alpha parameter of the design prior for group 2 (used if model2 = "beta").

b2d

Numeric scalar. Beta parameter of the design prior for group 2 (used if model2 = "beta").

dp2

Numeric scalar. True proportion for group 2 in the design prior (used if model2 = "Point").

n1

Numeric integer. Sample size for group 1.

n2

Numeric integer. Sample size for group 2.

type_rate

Character. Choose "positive" to control true/false positive rates or "negative" to control true/false negative rates.

plot_power

Logical; if TRUE, plot the power curve.

plot_rel

Logical; if TRUE, plot the grid for the values of BF across all possible combination of x1 and x2.

Details

1. Sample size determination mode (when n1 = NULL and n2 = NULL):

If no sample sizes are provided for the two groups, the function calculates the minimum sample sizes needed to achieve the desired configuration. The user must provide:

  • type_rate - either "positive" to control true/false positive rates or "negative" to control true/false negative rates.

  • true_rate - the targeted true positive or true negative rate (between 0.6 and 0.999).

  • threshold - the Bayes factor threshold for compelling evidence (must be > 1).

The function iteratively finds the smallest sample sizes for which the probability of obtaining compelling evidence meets or exceeds true_rate.

2. Fixed-sample analysis mode (when n1 and n2 are supplied):

If positive numeric sample sizes n1 and n2 are provided, the function computes the probabilities of obtaining compelling or misleading evidence for these fixed sample sizes. In this mode, type_rate and true_rate are ignored; only the Bayes factor threshold threshold is used.

Model specification:

The user must specify the analysis priors under the null and alternative hypotheses using Beta parameters:

  • a0, b0 - Beta parameters for the null hypothesis prior.

  • a1, b1 - Beta parameters for the analysis prior of group 1 under the alternative hypothesis.

  • a2, b2 - Beta parameters for the analysis prior of group 2 under the alternative hypothesis.

Design priors for the alternative hypothesis can optionally be specified:

  • prior_design_1, a1d, b1d, dp1 - design prior for group 1 ("same" uses the analysis prior, "beta" requires Beta parameters, "Point" uses a fixed proportion).

  • prior_design_2, a2d, b2d, dp2 - design prior for group 2.

Plotting:

If plot_power = TRUE, a power curve is plotted showing the probability of compelling evidence as a function of sample sizes. If plot_rel = TRUE, a grid of Bayes factors across possible outcomes is plotted.

Examples

Run this code
BFpower.props(
threshold = 3,
true_rate = 0.8,
a0 = 1,
b0 = 1,
a1 = 156,
b1 = 339,
a2 = 151,
b2 = 339,
plot_power = TRUE,
plot_rel = TRUE)

Run the code above in your browser using DataLab