Skip to content

BPower & sample size · power.bayes

Bayes factor design analysis (t-test)

How many participants does a Bayesian t-test need to reach compelling evidence?

For a JZS Bayesian t-test with a true effect δ, the probability that the Bayes factor reaches compelling evidence for the alternative (BF₁₀ > k), the probability of misleading evidence for the null (BF₀₁ > k), and the same two rates if the null is true — at a given sample size, or the smallest sample size reaching a target probability. Exact: the two-sided Bayes factor is monotone in |t|, so each probability is a noncentral-t tail beyond a computed threshold.

Verified in Python and R Python and R agree to 6 decimals Also called Bayesian power analysis, Bayes factor design analysis, BFDA…

A real result

Example “Solve n two sample”, recorded in both engines. In the app, “Try this example” loads it into Analyze.

Bayes factor design analysisRecorded · Python and R agreeRecorded 2026-11-17 · 11 values compared
R

n = 91 per group gives P(BF₁₀ > 3 | δ = 0.5) = 0.802 (JZS, r = 0.707)

Sample size (per group)
91
P(BF₁₀ > 3 | δ)
0.8017
P(BF₀₁ > 3 | δ)
0.0171
P(BF₀₁ > 3 | δ = 0)
0.7881
P(BF₁₀ > 3 | δ = 0)
0.0126

Plots

Evidence rates by sample sizeHow does power grow with sample size (or effect size), and where does it reach the target?
View data
ProbabilityOutcomeSample size (per group)
0.0391BF₁₀ > 3 if δ = 0.5 (compelling)3
0BF₀₁ > 3 if δ = 0.5 (misleading)3
0BF₀₁ > 3 if δ = 0 (compelling)3
0.0243BF₁₀ > 3 if δ = 0 (misleading)3
0.0477BF₁₀ > 3 if δ = 0.5 (compelling)4
0BF₀₁ > 3 if δ = 0.5 (misleading)4
0BF₀₁ > 3 if δ = 0 (compelling)4
0.0237BF₁₀ > 3 if δ = 0 (misleading)4
0.0566BF₁₀ > 3 if δ = 0.5 (compelling)5
0BF₀₁ > 3 if δ = 0.5 (misleading)5
0BF₀₁ > 3 if δ = 0 (compelling)5
0.0232BF₁₀ > 3 if δ = 0 (misleading)5
0.0658BF₁₀ > 3 if δ = 0.5 (compelling)6
0BF₀₁ > 3 if δ = 0.5 (misleading)6
0BF₀₁ > 3 if δ = 0 (compelling)6
0.0228BF₁₀ > 3 if δ = 0 (misleading)6
0.0752BF₁₀ > 3 if δ = 0.5 (compelling)7
0BF₀₁ > 3 if δ = 0.5 (misleading)7
0BF₀₁ > 3 if δ = 0 (compelling)7
0.0224BF₁₀ > 3 if δ = 0 (misleading)7
0.0945BF₁₀ > 3 if δ = 0.5 (compelling)9
0BF₀₁ > 3 if δ = 0.5 (misleading)9
0BF₀₁ > 3 if δ = 0 (compelling)9
0.0219BF₁₀ > 3 if δ = 0 (misleading)9
0.1044BF₁₀ > 3 if δ = 0.5 (compelling)10
0BF₀₁ > 3 if δ = 0.5 (misleading)10
0BF₀₁ > 3 if δ = 0 (compelling)10
0.0216BF₁₀ > 3 if δ = 0 (misleading)10
0.1348BF₁₀ > 3 if δ = 0.5 (compelling)13
0BF₀₁ > 3 if δ = 0.5 (misleading)13
0BF₀₁ > 3 if δ = 0 (compelling)13
0.0209BF₁₀ > 3 if δ = 0 (misleading)13
0.1555BF₁₀ > 3 if δ = 0.5 (compelling)15
0BF₀₁ > 3 if δ = 0.5 (misleading)15
0BF₀₁ > 3 if δ = 0 (compelling)15
0.0204BF₁₀ > 3 if δ = 0 (misleading)15
0.1871BF₁₀ > 3 if δ = 0.5 (compelling)18
0.0792BF₀₁ > 3 if δ = 0.5 (misleading)18
0.2358BF₀₁ > 3 if δ = 0 (compelling)18
0.0198BF₁₀ > 3 if δ = 0 (misleading)18
0.2191BF₁₀ > 3 if δ = 0.5 (compelling)21
0.1107BF₀₁ > 3 if δ = 0.5 (misleading)21
0.3717BF₀₁ > 3 if δ = 0 (compelling)21
0.0192BF₁₀ > 3 if δ = 0 (misleading)21
0.2728BF₁₀ > 3 if δ = 0.5 (compelling)26
0.1197BF₀₁ > 3 if δ = 0.5 (misleading)26
0.4887BF₀₁ > 3 if δ = 0 (compelling)26
0.0184BF₁₀ > 3 if δ = 0 (misleading)26
0.3262BF₁₀ > 3 if δ = 0.5 (compelling)31
0.1130BF₀₁ > 3 if δ = 0.5 (misleading)31
0.5582BF₀₁ > 3 if δ = 0 (compelling)31
0.0177BF₁₀ > 3 if δ = 0 (misleading)31
0.3891BF₁₀ > 3 if δ = 0.5 (compelling)37
0.0993BF₀₁ > 3 if δ = 0.5 (misleading)37
0.6140BF₀₁ > 3 if δ = 0 (compelling)37
0.0169BF₁₀ > 3 if δ = 0 (misleading)37
0.4594BF₁₀ > 3 if δ = 0.5 (compelling)44
0.0823BF₀₁ > 3 if δ = 0.5 (misleading)44
0.6591BF₀₁ > 3 if δ = 0 (compelling)44
0.0161BF₁₀ > 3 if δ = 0 (misleading)44

First 60 of 92 rows.

Evidence rates by sample size

n (per group)BF₁₀ > 3 | δBF₀₁ > 3 | δBF₀₁ > 3 | δ = 0BF₁₀ > 3 | δ = 0
30.0391000.0243
40.0477000.0237
50.0566000.0232
60.0658000.0228
70.0752000.0224
90.0945000.0219
100.1044000.0216
130.1348000.0209
150.1555000.0204
180.18710.07920.23580.0198
210.21910.11070.37170.0192
260.27280.11970.48870.0184
310.32620.11300.55820.0177
370.38910.09930.61400.0169
440.45940.08230.65910.0161
520.53450.06470.69600.0153
620.61900.04690.72940.0144
750.71220.03020.76070.0135
890.79190.01840.78520.0127
1070.86690.00950.80840.0118
1270.92170.00450.82750.0110
1520.96130.00170.84530.0102
1820.98430.00050.86120.0094
  • Thresholds: BF₁₀ > 3 when |t| > 2.5211; BF₀₁ > 3 when |t| < 1.2529.
  • Exact: each probability is a noncentral-t tail beyond the threshold (the simulation in Schönbrodt & Wagenmakers 2018 estimates the same quantities).
Python

n = 91 per group gives P(BF₁₀ > 3 | δ = 0.5) = 0.802 (JZS, r = 0.707)

Sample size (per group)
91
P(BF₁₀ > 3 | δ)
0.8017
P(BF₀₁ > 3 | δ)
0.0171
P(BF₀₁ > 3 | δ = 0)
0.7881
P(BF₁₀ > 3 | δ = 0)
0.0126

To keep this page light, the plots are shown once, under the R tab.

Evidence rates by sample size

n (per group)BF₁₀ > 3 | δBF₀₁ > 3 | δBF₀₁ > 3 | δ = 0BF₁₀ > 3 | δ = 0
30.0391000.0243
40.0477000.0237
50.0566000.0232
60.0658000.0228
70.0752000.0224
90.0945000.0219
100.1044000.0216
130.1348000.0209
150.1555000.0204
180.18710.07920.23580.0198
210.21910.11070.37170.0192
260.27280.11970.48870.0184
310.32620.11300.55820.0177
370.38910.09930.61400.0169
440.45940.08230.65910.0161
520.53450.06470.69600.0153
620.61900.04690.72940.0144
750.71220.03020.76070.0135
890.79190.01840.78520.0127
1070.86690.00950.80840.0118
1270.92170.00450.82750.0110
1520.96130.00170.84530.0102
1820.98430.00050.86120.0094
  • Thresholds: BF₁₀ > 3 when |t| > 2.5211; BF₀₁ > 3 when |t| < 1.2529.
  • Exact: each probability is a noncentral-t tail beyond the threshold (the simulation in Schönbrodt & Wagenmakers 2018 estimates the same quantities).

Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.

Worked examples in the app

  • Solve n two sampleNo data needed
  • Probability paired greaterNo data needed
  • Solve n one sample wideNo data needed

In the guides

Where it sits in the decision guides

  • Sample-size planning · Statistics Guide · Step 0 — Prepare your data
  • Sample size and power · Statistics Guide · Additional considerations

Choices you make

hypothesis

Solve fordefault n

Find the sample size that meets your evidence goals, or the probabilities of evidence at a given size.

  • Sample size(default) — The smallest n where compelling evidence for H₁ is at least as likely as the target.
  • Probabilities at a sample size — Compelling and misleading evidence rates at your n.
Designdefault two-sample

Two independent groups, paired measurements, or one sample.

  • Two independent groups (n per group)(default) — Plans n per group for two independent groups, using the two-sample Bayes factor.
  • Paired (n pairs) — Plans the number of pairs, using the paired Bayes factor on the differences.
  • One sample (n observations) — Plans n for one group's mean against a fixed value.
True effect δ (Cohen's d)default 0.5

The standardized effect you plan for (the smallest effect worth detecting, or a cautious estimate).

Analysis prior widthdefault medium

The Cauchy prior width the analysis will use (the same choice as in the Bayesian t-test).

  • Medium (r = √2/2)(default) — Cauchy width √2/2; the usual choice for typical effects.
  • Wide (r = 1) — Cauchy width 1; pick it if you expect larger effects.
  • Ultrawide (r = √2) — Cauchy width √2; pick it if you expect very large effects, at a cost for small ones.
  • Custom — Uses the width you enter; pick it to match your planned analysis.
Prior scale rdefault 0.707

Cauchy scale of the analysis prior on δ.

Alternative hypothesisdefault two-sided

Which direction counts as evidence. Keep two-sided unless you fixed the direction before seeing the data.

  • δ ≠ 0(default) — Plans for a Bayes factor that allows an effect in either direction; the usual choice.
  • δ > 0 (directional) — Plans for a Bayes factor with its prior on positive effects only; pick it if you fixed the direction in advance.
Evidence threshold kdefault 6

Compelling evidence means BF > k: 3 moderate, 6 or 10 common in planning, 30 strong.

Target probabilitydefault 0.8

Required probability of BF₁₀ > k when the effect is δ.

Sample size (per group, pairs or observations)default 50

Sample size per group, pairs or observations (when not solving for it).

Advanced

Largest sample size searcheddefault 2000

Largest sample size the search will consider.

What it reports

n
How many independent units the analysis used; it sets precision and power.
p_h1_compelling
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
p_h1_misleading
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
p_h0_compelling
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
p_h0_misleading
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
t_h1
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
t_h0
Plans a study by the chance its Bayes factor reaches a threshold: for H₁ when the effect is real, and for H₀.
k
How many groups, studies or clusters the analysis used. Many methods are less reliable when k is small.
delta
Asks whether rows within groups are closer than random sets of the same sizes; A = 1 − δ/E(δ).
r
A number from −1 to 1 for how closely two variables move together; Pearson measures straight-line association.
target
Chance of compelling evidence (BF above the threshold, if H₁ is true) the sample size must reach. Empty when solving for probabilities.

Python and R

Python and R agree to 6 decimals (relative tolerance 1e-7). Python uses numpy, scipy, codesplash; R uses stats, codesplashr.

Default traps between the two languages

  • Probabilities use the noncentral t CDF (scipy/Boost vs R's AS 243); thresholds are shared and agree to 1e-10.
Python

The exact script CodeSplash ran for example “Solve n two sample” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0

# Bayes factor design analysis (t-test)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.bayes 1.0.0 · spec ad1ca0c6338dbdb2
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
import math

import numpy as np

import codesplash as cs
from codesplash.stats import bayes as bf  # exact Bayes factor design analysis (twin of R cs_bayes_power)

# %% Inputs
solve_for = "n"  # n | probability
design = "two-sample"
delta = 0.5
r = bf.prior_scale("t", "medium", 0.707)
alternative = "two-sided"
k = 3
target = 0.8
warnings = []
n_min = 3 if design != "two-sample" else 2

# %% Solve
if solve_for == "n":
    n = bf.power_n(design, delta, r, k, target, alternative, n_min=n_min, n_max=int(2000))
    if n is None:
        warnings.append(f"P(BF₁₀ > {k:g}) does not reach {target:.0%} below n = {int(2000):,}.")
        n = int(2000)
else:
    n = int(50)
row = bf.bayes_power(design, delta, r, k, [n], alternative)[0]

# %% Curves
top = max(int(n * 2), 20)
ns = np.unique(np.round(np.exp(np.linspace(math.log(n_min + 1), math.log(top), 24))).astype(int))
curve = bf.bayes_power(design, delta, r, k, [int(x) for x in ns], alternative)
series = [
    ("h1_bf10", f"BF₁₀ > {k:g} if δ = {delta:g} (compelling)"),
    ("h1_bf01", f"BF₀₁ > {k:g} if δ = {delta:g} (misleading)"),
    ("h0_bf01", f"BF₀₁ > {k:g} if δ = 0 (compelling)"),
    ("h0_bf10", f"BF₁₀ > {k:g} if δ = 0 (misleading)"),
]
unit = {"two-sample": "per group", "paired": "pairs", "one-sample": "observations"}[design]

# %% Result
cs.publish({
    "method": "power.bayes",
    "methodVersion": "1.0.0",
    "title": "Bayes factor design analysis",
    "engine": cs.engine_info("scipy"),
    "summary": (
        f"With n = {n:,} ({unit}) and a true effect δ = {delta:g}, the Bayes factor reaches BF₁₀ > {k:g} with probability "
        f"{row['h1_bf10']:.3f} and misleadingly favors the null (BF₀₁ > {k:g}) with probability {row['h1_bf01']:.3f}. "
        f"If there is no effect, BF₀₁ > {k:g} with probability {row['h0_bf01']:.3f} and BF₁₀ > {k:g} with probability {row['h0_bf10']:.3f}."
    ),
    "apa": f"n = {n:,} {unit} gives P(BF₁₀ > {k:g} | δ = {delta:g}) = {row['h1_bf10']:.3f} (JZS, r = {r:.3g})",
    "statistics": [
        {"key": "n", "label": f"Sample size ({unit})", "value": n, "format": "integer"},
        {"key": "p_h1_compelling", "label": f"P(BF₁₀ > {k:g} | δ)", "value": row["h1_bf10"]},
        {"key": "p_h1_misleading", "label": f"P(BF₀₁ > {k:g} | δ)", "value": row["h1_bf01"]},
        {"key": "p_h0_compelling", "label": f"P(BF₀₁ > {k:g} | δ = 0)", "value": row["h0_bf01"]},
        {"key": "p_h0_misleading", "label": f"P(BF₁₀ > {k:g} | δ = 0)", "value": row["h0_bf10"]},
    ],
    "tables": [{"key": "curve", "title": "Evidence rates by sample size",
                "columns": [{"key": "n", "label": f"n ({unit})", "type": "integer"},
                            {"key": "h1_bf10", "label": f"BF₁₀ > {k:g} | δ", "type": "number"},
                            {"key": "h1_bf01", "label": f"BF₀₁ > {k:g} | δ", "type": "number"},
                            {"key": "h0_bf01", "label": f"BF₀₁ > {k:g} | δ = 0", "type": "number"},
                            {"key": "h0_bf10", "label": f"BF₁₀ > {k:g} | δ = 0", "type": "number"}],
                "rows": [{key: c[key] for key in ("n", "h1_bf10", "h1_bf01", "h0_bf01", "h0_bf10")} for c in curve]}],
    "warnings": warnings,
    "notes": [
        f"Thresholds: BF₁₀ > {k:g} when |t| > {row['t_h1']:.4f}" + (f"; BF₀₁ > {k:g} when |t| < {row['t_h0']:.4f}." if row["t_h0"] is not None else f"; BF₀₁ never exceeds {k:g} at this n."),
        "Exact: each probability is a noncentral-t tail beyond the threshold (the simulation in Schönbrodt & Wagenmakers 2018 estimates the same quantities).",
    ],
    "charts": [cs.chart(
        "rates", "power-curve", "Evidence rates by sample size",
        {"x": cs.col(f"Sample size ({unit})", [c["n"] for c in curve for _ in series]),
         "power": cs.col("Probability", [c[key] for c in curve for key, _ in series]),
         "series": cs.col("Outcome", [label for _ in curve for _, label in series], levels=[label for _, label in series])},
        controls={"target": target if solve_for == "n" else 0.8, "xLog": True},
    )],
    "values": {
        "n": n, "p_h1_compelling": row["h1_bf10"], "p_h1_misleading": row["h1_bf01"], "p_h0_compelling": row["h0_bf01"],
        "p_h0_misleading": row["h0_bf10"], "t_h1": row["t_h1"], "t_h0": row["t_h0"], "k": k, "delta": delta, "r": r,
        "target": target if solve_for == "n" else None,
    },
})
R

The exact script CodeSplash ran for example “Solve n two sample” · R version 4.5.1 (2025-06-13)

# Bayes factor design analysis (t-test)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method power.bayes 1.0.0 · spec ad1ca0c6338dbdb2
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr) # cs_bayes_power, cs_bayes_power_n, cs_bayes_prior_scale (twins of codesplash.stats.bayes)

# %% Inputs
solve_for <- "n"  # n | probability
design <- "two-sample"
delta <- 0.5
r <- cs_bayes_prior_scale("t", "medium", 0.707)
alternative <- "two-sided"
k <- 3
target <- 0.8
warnings <- list()
n_min <- if (design != "two-sample") 3L else 2L
fmtk <- format(k)

# %% Solve
if (solve_for == "n") {
  n <- cs_bayes_power_n(design, delta, r, k, target, alternative, n_min = n_min, n_max = as.integer(2000))
  if (is.null(n)) {
    warnings <- c(warnings, sprintf("P(BF₁₀ > %s) does not reach %.0f%% below n = %s.", fmtk, 100 * target,
                                    format(as.integer(2000), big.mark = ",")))
    n <- as.integer(2000)
  }
} else {
  n <- as.integer(50)
}
row <- cs_bayes_power(design, delta, r, k, n, alternative)[[1]]

# %% Curves
top <- max(as.integer(n * 2), 20L)
ns <- sort(unique(as.integer(round(exp(seq(log(n_min + 1), log(top), length.out = 24))))))
curve <- cs_bayes_power(design, delta, r, k, ns, alternative)
keys <- c("h1_bf10", "h1_bf01", "h0_bf01", "h0_bf10")
labels <- c(sprintf("BF₁₀ > %s if δ = %s (compelling)", fmtk, format(delta)),
            sprintf("BF₀₁ > %s if δ = %s (misleading)", fmtk, format(delta)),
            sprintf("BF₀₁ > %s if δ = 0 (compelling)", fmtk),
            sprintf("BF₁₀ > %s if δ = 0 (misleading)", fmtk))
unit <- switch(design, "two-sample" = "per group", paired = "pairs", "one-sample" = "observations")
nf <- format(n, big.mark = ",")

# %% Result
cs_publish(list(
  method = "power.bayes",
  methodVersion = "1.0.0",
  title = "Bayes factor design analysis",
  engine = cs_engine_info("stats"),
  summary = sprintf(
    "With n = %s (%s) and a true effect δ = %s, the Bayes factor reaches BF₁₀ > %s with probability %.3f and misleadingly favors the null (BF₀₁ > %s) with probability %.3f. If there is no effect, BF₀₁ > %s with probability %.3f and BF₁₀ > %s with probability %.3f.",
    nf, unit, format(delta), fmtk, row$h1_bf10, fmtk, row$h1_bf01, fmtk, row$h0_bf01, fmtk, row$h0_bf10),
  apa = sprintf("n = %s %s gives P(BF₁₀ > %s | δ = %s) = %.3f (JZS, r = %s)", nf, unit, fmtk, format(delta), row$h1_bf10, format(signif(r, 3))),
  statistics = list(
    list(key = "n", label = sprintf("Sample size (%s)", unit), value = n, format = "integer"),
    list(key = "p_h1_compelling", label = sprintf("P(BF₁₀ > %s | δ)", fmtk), value = row$h1_bf10),
    list(key = "p_h1_misleading", label = sprintf("P(BF₀₁ > %s | δ)", fmtk), value = row$h1_bf01),
    list(key = "p_h0_compelling", label = sprintf("P(BF₀₁ > %s | δ = 0)", fmtk), value = row$h0_bf01),
    list(key = "p_h0_misleading", label = sprintf("P(BF₁₀ > %s | δ = 0)", fmtk), value = row$h0_bf10)
  ),
  tables = list(list(key = "curve", title = "Evidence rates by sample size",
    columns = list(list(key = "n", label = sprintf("n (%s)", unit), type = "integer"),
                   list(key = "h1_bf10", label = sprintf("BF₁₀ > %s | δ", fmtk), type = "number"),
                   list(key = "h1_bf01", label = sprintf("BF₀₁ > %s | δ", fmtk), type = "number"),
                   list(key = "h0_bf01", label = sprintf("BF₀₁ > %s | δ = 0", fmtk), type = "number"),
                   list(key = "h0_bf10", label = sprintf("BF₁₀ > %s | δ = 0", fmtk), type = "number")),
    rows = lapply(curve, function(cc) list(n = cc$n, h1_bf10 = cc$h1_bf10, h1_bf01 = cc$h1_bf01, h0_bf01 = cc$h0_bf01, h0_bf10 = cc$h0_bf10)))),
  warnings = warnings,
  notes = list(
    paste0(sprintf("Thresholds: BF₁₀ > %s when |t| > %.4f", fmtk, row$t_h1),
           if (!is.null(row$t_h0)) sprintf("; BF₀₁ > %s when |t| < %.4f.", fmtk, row$t_h0) else sprintf("; BF₀₁ never exceeds %s at this n.", fmtk)),
    "Exact: each probability is a noncentral-t tail beyond the threshold (the simulation in Schönbrodt & Wagenmakers 2018 estimates the same quantities)."
  ),
  charts = list(cs_chart("rates", "power-curve", "Evidence rates by sample size",
    list(x = cs_col(sprintf("Sample size (%s)", unit), as.numeric(rep(vapply(curve, function(cc) cc$n, numeric(1)), each = 4))),
         power = cs_col("Probability", unlist(lapply(curve, function(cc) vapply(keys, function(key) cc[[key]], numeric(1))), use.names = FALSE)),
         series = cs_col("Outcome", rep(labels, times = length(curve)), levels = labels)),
    controls = list(target = if (solve_for == "n") target else 0.8, xLog = TRUE))),
  values = list(
    n = n, p_h1_compelling = row$h1_bf10, p_h1_misleading = row$h1_bf01, p_h0_compelling = row$h0_bf01,
    p_h0_misleading = row$h0_bf10, t_h1 = row$t_h1, t_h0 = row$t_h0, k = k, delta = delta, r = r,
    target = if (solve_for == "n") target else NULL
  )
))

Sources

  • Schönbrodt, F. D., & Wagenmakers, E.-J. (2018). Bayes factor design analysis: planning for compelling evidence. Psychonomic Bulletin & Review, 25, 128–142.
  • Rouder, J. N., Speckman, P. L., Sun, D., Morey, R. D., & Iverson, G. (2009). Bayesian t tests for accepting and rejecting the null hypothesis. Psychonomic Bulletin & Review, 16, 225–237.

From the CodeSplash method registry · power.bayes v1.0.0.