Learn R Programming

BayesPower (version 1.0.2)

BFpower.ttest.TwoSample: Sample Size Determination for the Two-Sample Bayesian t-Test

Description

Perform sample size determination or calculate the probabilities of obtaining compelling or misleading evidence for a two-sample Bayesian t-test. Supports point-null and interval-null hypotheses, and allows specifying analysis and design priors.

Usage

BFpower.ttest.TwoSample(
  alternative,
  ROPE = NULL,
  threshold,
  true_rate,
  false_rate,
  prior_analysis,
  location,
  scale,
  dff,
  prior_design = NULL,
  location_d,
  scale_d,
  dff_d,
  N1 = NULL,
  N2 = NULL,
  r = NULL,
  type_rate = "positive",
  plot_power = FALSE,
  plot_rel = FALSE
)

Value

An object of class BFpower_t containing:

type

Character string describing the test type.

alternative

alternative hypothesis ("two.sided", "greater", or "less").

ROPE

Interval bounds under the null used, if any.

analysis_h1

List with the analysis prior parameters: prior_analysis, location, scale, and optionally dff.

design_h1

List with the design prior parameters: prior_design, location, scale, and optionally dff (or NULL if not provided).

results

Data frame with probabilities of compelling/misleading evidence.

threshold

Threshold of compelling evidence.

plot_power

Logical flag for plotting power.

plot_rel

Logical flag for plotting the relationship between BF and t-value.

Arguments

alternative

Character. The direction of the alternative hypothesis: two-sided ("two.sided"), right-sided ("greater"), or left-sided ("less").

ROPE

Optional numeric. Bounds for an interval null:

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

threshold

Numeric scalar. Threshold for compelling evidence (must be > 1).

true_rate

Numeric scalar. Target true positive or negative rate .

false_rate

Numeric scalar. Target false positive or negative rate .

prior_analysis

Character. Analysis prior under the alternative hypothesis: "Normal", "Moment", or "t-distribution".

location

Numeric scalar. Location parameter for the analysis prior.

scale

Numeric scalar > 0. Scale parameter for the analysis prior.

dff

Numeric scalar. Degrees of freedom for the analysis prior (required if prior_analysis = "t-distribution"; ignored otherwise).

prior_design

Optional character. Design prior under the alternative: "Normal", "Moment", "t-distribution", or "Point".

location_d

Numeric scalar. Location parameter for the design prior.

scale_d

Numeric scalar > 0. Scale parameter for the design prior.

dff_d

Numeric scalar. Degrees of freedom for the design prior (required if prior_design = "t-distribution"; ignored otherwise).

N1

Numeric integer. Sample size for group 1 (used if r = NULL).

N2

Numeric integer. Sample size for group 2 (used if r = NULL).

r

Optional numeric scalar. Ratio of sample size N2 / N1 (used if N1 and N2 are NULL).

type_rate

Character, either "positive" or "negative"; determines whether to control true/false positive or true/false negative rates .

plot_power

Logical. If TRUE, a plot of the power or probability of compelling evidence is generated.

plot_rel

Logical. Whether the relationship between the BF and data is plotted..

Details

1. Sample size determination mode (when N1 = NULL and N2 = NULL, but r is provided):

If no sample sizes are provided, the function calculates the minimum required sample sizes for both groups. In this mode, the user must supply:

  • 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).

  • r - the allocation ratio of group 2 to group 1 sample sizes (N2/N1).

The function iteratively finds the smallest sample sizes N1 and N2 = r * N1 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 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 those fixed sample sizes. In this mode, the arguments type_rate, true_rate, and false_rate are ignored; only the Bayes factor threshold threshold is used.

Analysis Priors:

The analysis prior specifies the prior distribution of the effect under the alternative hypothesis. The user must provide:

  • prior_analysis - the type of prior: "Normal", "Moment" (normal-moment prior), or "t-distribution".

  • location - the mean or location of the prior.

  • scale - the standard deviation or scale (must be positive).

  • dff - degrees of freedom (required if prior_analysis = "t-distribution").

Design Priors (optional):

A design prior can be supplied to reflect uncertainty about the effect size during study planning. If provided, the following must be supplied:

  • prior_design - the type of design prior: "Normal", "Moment", "t-distribution", or "Point".

  • location_d - the location of the design prior.

  • scale_d - the scale parameter (positive for all models except "Point").

  • dff_d - degrees of freedom for "t-distribution" design priors.

interval null Hypothesis:

The argument ROPE specifies the bounds of an interval null hypothesis. If ROPE is provided, the function evaluates the Bayes factor for an interval null hypothesis. For a point-null hypothesis, ROPE should be left as NULL.

Plotting:

If plot_power = TRUE, the function plots the probability of compelling evidence as a function of the sample sizes. If plot_rel = TRUE, the relationship between BF and data is plotted.

Examples

Run this code
BFpower.ttest.TwoSample(
 alternative = "two.sided",
 ROPE = c(-0.36, 0.36),
 threshold = 3,
 true_rate = 0.8,
 false_rate = 0.05,
 prior_analysis = "Normal",
 location = -0.23,
 scale = 0.2,
 dff = 1,
 type_rate = "negative",
 r = 1)

Run the code above in your browser using DataLab