bfttest: Bayesian Sequential t-Test

View source: R/bayestest.R

bfttestR Documentation

Bayesian Sequential t-Test

Description

Calculates sequential Bayes Factors for t-tests (one-sample, paired, or independent samples), showing how evidence evolves as data accumulates. Uses the BFDA package for Bayes Factor calculations.

Usage

bfttest(
  x = NULL,
  y = NULL,
  formula = NULL,
  data = NULL,
  alternative = c("two.sided", "less", "greater"),
  mu = 0,
  prior.loc = 0,
  prior.r = 0.1,
  nstart = "auto",
  exact = TRUE
)

Arguments

x

A numeric vector of observations or a formula for independent samples test

y

Optional numeric vector for paired samples test

formula

Formula of form response ~ group where group has exactly 2 levels

data

Optional data frame containing the variables in formula

alternative

Direction of alternative hypothesis: "two.sided", "greater", or "less"

mu

Null hypothesis value (default = 0)

prior.loc

Location parameter for Cauchy prior (default = 0)

prior.r

Scale parameter for Cauchy prior (default = 0.1)

nstart

Minimum observations before first BF calculation ("auto" or >= 2)

exact

Logical. If TRUE, calculates BF for all points

Value

A list of class "seqbf" containing:

  • t-value: Sequential t-statistics

  • p-value: Sequential p-values

  • BF: Sequential Bayes Factors

  • test type: "one-sample", "paired", or "independent"

  • prior: List with prior distribution details

  • sample size: Number of observations

  • alternative: Chosen alternative hypothesis

Examples

# One-sample test
x <- rnorm(30, 0.5, 1)
result1 <- bfttest(x, alternative = "greater")

# Independent samples test
group <- rep(c("A", "B"), each = 15)
values <- c(rnorm(15), rnorm(15, 0.5))
df <- data.frame(values = values, group = group)
result2 <- bfttest(values ~ group, data = df)

# Paired samples test
pre <- rnorm(20)
post <- pre + rnorm(20, 0.5)
result3 <- bfttest(pre, post)

mrzdcmps/changeofevidence documentation built on Feb. 27, 2025, 3:10 a.m.