Perform sample size determination or the calculation of compelling and misleading evidence for a Bayesian test of a single proportion.
BFpower.bin(
alternative,
threshold,
h0,
true_rate,
false_rate,
prior_analysis,
alpha,
beta,
scale,
prior_design = NULL,
alpha_d,
beta_d,
location_d,
scale_d,
N = NULL,
ROPE = NULL,
type_rate = "positive",
plot_power = FALSE,
plot_rel = FALSE
)A list of class "BFpower_bin" containing:
type: Test type ("One proportion").
alternative: alternative hypothesis.
h0: The proportion under the null hypothesis.
analysis_h1: List describing the analysis prior, containing
prior (prior distribution), alpha (alpha parameter),
beta (beta parameter), and scale (scale parameter).
design_h1: List describing the design prior (if provided), containing
prior (prior distribution), alpha (alpha parameter),
beta (beta parameter), and scale (scale parameter).
results: Data frame of probabilities of compelling/misleading evidence and the required or supplied sample size.
threshold: Compelling-evidence threshold.
plot_power: Logical, whether power curves are plotted.
plot_rel: Logical, whether the relationship between the BF and data is plotted.
If sample size determination fails, the function returns NaN and prints a message.
Character. The direction of the alternative hypothesis : two-sided ("two.sided"), right-sided ("greater"), or left-sided ("less").
Numeric scalar. Threshold for compelling evidence (must be > 1).
Numeric scalar. Null proportion value for the test (numeric scalar between 0.1 and 0.9).
Numeric scalar. Targeted true positive rate or true negative rate .
Numeric scalar. Targeted false positive rate or false negative rate .
Character. Analysis prior under the alternative hypothesis: "beta" or "Moment".
Numeric scalar. Parameter for the analysis beta prior (used when prior_analysis = "beta").
Numeric scalar. Parameter for the analysis beta prior (used when prior_analysis = "beta").
Numeric scalar. Scale parameter for the analysis moment prior (used when prior_analysis = "Moment").
Character. Design prior under the alternative hypothesis: "beta", "Moment", or "Point".
Numeric scalar. Parameter for the design beta prior (used when prior_design = "beta").
Numeric scalar. Parameter for the design beta prior (used when prior_design = "beta").
Numeric scalar. Proportion value for the design point prior (prior_design = "Point"). Represents the true proportion under the alternative hypothesis.
Numeric scalar. Scale parameter for the design moment prior (used when prior_design = "Moment").
Numeric integer. Sample size. If NULL, sample size determination is performed.
Numeric vector. Numeric bounds for the interval null (used when computing interval Bayes factors).
For hypothesis = "two.sided", must be a numeric vector of length 2 with distinct finite values.
For "greater", must be a single numeric scalar > 0.
For "less", must be a single numeric scalar < 0.
Character. Either "positive" (controls true/false positive rates) or "negative" (controls true/false negative rates).
Logical. Whether to plot power curves when sample size determination is requested.
Logical. Whether to plot probability of misleading evidence.
1. Sample size determination mode (when N = NULL):
If no sample size is provided, the function calculates the minimum sample size needed to achieve the desired configuration below. 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).
false_rate - the acceptable false positive or false negative rate (between 0.001 and 0.1).
threshold - the Bayes factor threshold for compelling evidence (must be > 1).
The function iteratively finds the smallest sample size for which the probability of obtaining compelling evidence meets or exceeds true_rate, while the probability of misleading evidence does not exceed false_rate.
2. Fixed-sample analysis mode (when N is supplied):
If a positive numeric sample size N is provided, the function computes the probabilities of obtaining compelling or misleading evidence for that fixed sample size. In this mode, type_rate, true_rate, and false_rate are ignored; only the Bayes factor threshold threshold is used.
Model specification:
The user must specify the analysis prior under the alternative hypothesis using prior_analysis:
prior_analysis = "beta": requires alpha and beta parameters (shape parameters of the beta distribution).
prior_analysis = "Moment": requires scale parameter (scale of the moment prior).
The design prior under the alternative hypothesis can optionally be specified using prior_design:
"beta": requires alpha_d and beta_d.
"Moment": requires scale_d.
"Point": requires location_d, representing the true proportion under the alternative hypothesis.
If prior_design is NULL, no design prior is used.
interval null Hypothesis:
If ROPE is provided, the function evaluates the Bayes factor for an interval null. Otherwise, a point-null hypothesis is assumed.
Hypothesis:
The function supports one-sided ("greater" or "less") and two-sided ("two.sided") tests. Design prior and interval null bounds must be consistent with the directionality of the hypothesis.
Plotting:
If plot_power = TRUE, the function plots the probability of compelling evidence as a function of sample size. If plot_rel = TRUE, the relationship between the Bayes factor and the number of successes (proportion) is plotted.
BFpower.bin(
alternative = "greater",
threshold = 3,
true_rate = 0.8,
false_rate = 0.05,
h0 = 0.5,
prior_analysis = "beta",
alpha = 1,
beta = 1,
plot_rel = TRUE,
plot_power = TRUE)
Run the code above in your browser using DataLab