Learn R Programming

BayesPower (version 1.0.2)

BFpower.ttest.OneSample: Sample Size Determination for the One-Sample Bayesian t-Test

Description

Perform sample size determination or calculate the probability of obtaining compelling or misleading evidence for a one-sample Bayesian t-test. Can handle both point-null and interval-null hypothesis, and allows specifying analysis and design priors.

Usage

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

Value

An object of class BFpower_t (a list) containing:

type

Character, always "One-sample t-test".

alternative

Character, the direction of the alternative hypothesis.

ROPE

Optional numeric vector for interval null bounds.

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 of probabilities: compelling/misleading evidence, or NaN if calculation fails.

threshold

Numeric, threshold of compelling evidence.

plot_power

Logical, whether to plot the power curve.

plot_rel

Logical, whether the relationship between the BF and t-value is plotted.

Arguments

alternative

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

ROPE

Optional numeric vector. Bounds for an interval null hypothesis.

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

prior_analysis

Character. The analysis prior under the alternative hypothesis: "Normal", "Moment" (normal-moment prior), or "t-distribution".

location

Numeric scaler. Location parameter for the analysis prior under the alternative hypothesis.

scale

Numeric scaler. Scale parameter for the analysis prior under the alternative hypothesis (must be > 0).

dff

Numeric scaler. Degrees of freedom for the analysis prior under the alternative hypothesis (required if prior_analysis = "t-distribution").

prior_design

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

location_d

Numeric scaler. Location parameter for the design prior under the alternative hypothesis.

scale_d

Numeric scaler. Scale parameter for the design prior under the alternative hypothesis.

dff_d

Numeric scaler. Degrees of freedom for the design prior under the alternative hypothesis (required if prior_design = "t-distribution").

N

Numeric integer. Sample size.

type_rate

Character. Either "positive" (controls true/false positive rates) or "negative" (controls true/false negative rates).

true_rate

Numeric scaler. Target true positive or negative rate (between 0.6 and 0.999).

false_rate

Numeric scaler. Target false positive or false negative rate (between 0.001 and 0.1).

threshold

Numeric scaler. Threshold of compelling evidence (must be > 1).

plot_power

Logical. If TRUE, plots power curve.

plot_rel

Logical. If TRUE, plots the relationship between the BF and data.

Details

1. Sample size determination mode (when N = NULL):

If no sample size is provided, the function determines the minimum sample size. In this mode, the user must supply the following arguments:

  • 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, 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 sample size. If plot_rel = TRUE, the relationship betwwen the BF and data is plotted.

Examples

Run this code
BFpower.ttest.OneSample(
 alternative = "two.sided",
 threshold = 3,
 true_rate = 0.8,
 false_rate = 0.05,
 prior_analysis = "t-distribution",
 location = 0,
 scale = 0.707,
 dff = 1
)

Run the code above in your browser using DataLab