Skip to content

BCompare groups · Guide test 311

Jeffreys–Zellner–Siow Bayesian t test

Compares a zero standardized mean effect with a prior distributed alternative using a Bayes factor.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Jeffreys–Zellner–Siow Bayesian t test

20
20
0.60
1.0
1.0
0.71

Cauchy prior on the standardized effect: medium √2/2 ≈ 0.707, wide 1, ultrawide √2.

0.050

Your data

Drag a point or use ↑/↓ to change it
Group 1 · n = 20 · mean 0.36Group 2 · n = 20 · mean −0.20

If H₀ were true

t = 1.66
  1. The reference: how t varies across samples when H₀ is true.
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .105).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The evidence

prior (dashed) · posteriorextremevery strongstrongmoderateanecdotalanecdotalmoderatestrongvery strongextreme1/1001/301/101/3131030100← evidence for H₀evidence for H₁ →

BF₁₀ = 0.91: anecdotal evidence for H₀ (prior: Cauchy(0, 0.707) on δ). The ratio of the two dots at δ = 0 is the Bayes factor (Savage–Dickey). Unlike p, the Bayes factor can favor H₀, and it moves with the prior's width.

The formula

BF10=∫Tν(t; δN) Cauchy(δ;0,r) dδTν(t; 0),N=n1n2n1+n2\mathrm{BF}_{10}=\frac{\int T_\nu\big(t;\,\delta\sqrt{N}\big)\,\mathrm{Cauchy}(\delta;0,r)\,d\delta}{T_\nu(t;\,0)},\qquad N=\frac{n_1n_2}{n_1+n_2}

With your numbers

t=1.66, ν=38, N=10, r=0.71 ⇒ BF10=0.91t = 1.66,\ \nu = 38,\ N = 10,\ r = 0.71\ \Rightarrow\ \mathrm{BF}_{10} = 0.91
Tν(t; δN)T_\nu(t;\,\delta\sqrt N)
the (noncentral) t density of the observed t if the effect is δ
Cauchy(0,r)\mathrm{Cauchy}(0,r)
the prior on the standardized effect δ; r = √2/2 is 'medium'

The verdict

t(38) = 1.66, p = .105, BF₁₀ = 0.91

p > α = .050: compatible with H₀

Effect size: Bayes factor (H₁ over H₀) BF₁₀ = 0.908

BF10 above 1 favors a difference, below 1 favors none; around 1 the data cannot tell. It depends on r, so report it and a robustness check.

Statistic
1.661
p-value
0.1049
Jeffreys–Zellner–Siow Bayesian t test on Group 1: n = 20; Group 2: n = 20: t(38) = 1.66, p = .105, BF10 = 0.91. The p-value is above α = .050, so the data are compatible with H0.

Jeffreys–Zellner–Siow Bayesian t test on Group 1: n = 20; Group 2: n = 20: t(38) = 1.66, p = .105, BF₁₀ = 0.91. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: standardized mean effect δ=0; H1: δ has a centered Cauchy prior with scale r.

Assumptions

A specified likelihood and prior under each hypothesis; observations satisfy the chosen sampling model. Bayes factors measure relative predictive evidence and are not p values. Normal observations/differences for the t model; a common variance for the classical independent-groups version.

Formula

BF10=∫0∞(1+n∗g)−1/2[1+t2/{ν(1+n∗g)}]−(ν+1)/2π(g) dg[1+t2/ν]−(ν+1)/2g∼IG(1/2,r2/2)\begin{gathered}BF_{10}=\frac{\int_0^\infty(1+n_*g)^{-1/2}[1+t^2/\{\nu(1+n_*g)\}]^{-(\nu+1)/2}\pi(g)\,dg}{[1+t^2/\nu]^{-(\nu+1)/2}}\\[5pt] g\sim IG(1/2,r^2/2)\end{gathered}

Parameters and notation

t,ν are the corresponding classical t statistic/df; n*=n for one-sample/paired tests or n1n2/(n1+n2) for independent groups. Mixing δ|g~N(0,g) gives Cauchy(0,r). Common default r=√2/2; state it. IG(a,b) has density bᵃg^(−a−1)exp(−b/g)/Γ(a). Common nuisance mean/scale priors are handled consistently across hypotheses.

Structure of the method

Integrate the normal-model likelihood over a centered Cauchy standardized-effect prior and compatible nuisance priors, then divide by the null-model marginal likelihood. The resulting Bayes factor compares predictive models; it is not a posterior probability or a p value.

Estimated and nuisance parameters

Means, scale and standardized effect are model parameters integrated over their priors, not simply plugged into a fitted alternative likelihood. The observed t statistic and sample-size factor can summarize the data for the analytic construction. Prior width r is a user-specified hyperparameter, not a data-estimated standard error.

Settings and design choices

Prespecify paired/independent design, null value, prior width and any directional/interval hypothesis. The classical independent-groups JZS model assumes a common variance and is not automatically Welch’s unequal-variance test. Record the Bayes-factor orientation and distinguish evidence calculation from requesting posterior samples.

Fitting and adaptation

Adaptation means choosing a justified likelihood/prior before inspecting evidence and checking a prespecified prior-sensitivity range. Validate numerical integration or Monte Carlo error where relevant. If a new domain violates normality or common variance, use a separately specified robust/heteroscedastic Bayesian model rather than relabeling the same formula.

Sensitivity and robustness

Wide alternatives spread prior mass and can favor the point null more strongly than narrow alternatives for the same data. Outliers, dependence and prior-model mismatch matter. BF10 below one supports the null relative to that alternative, while posterior model probabilities additionally require prior model odds; neither establishes practical equivalence automatically.

How to use and calibrate

Numerically integrate or use a validated JZS implementation; BF10>1 favors H1,BF10<1 favors H0. Assess prior sensitivity.

Example application

Quantify evidence for either a mean difference or the point null.

Interpretation and pitfalls

Watch out

The result depends on prior scale and normal/common-variance model. It is not automatically a Bayesian version of Welch’s test.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Independent-group JZS Bayesian t test with medium Cauchy standardized-effect prior. Output is evidence ratio BF10 versus the null, not a frequentist p-value; prior scale matters.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: BayesFactor

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(BayesFactor::ttestBF(x=x,y=y,paired=FALSE,rscale="medium"))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Validated — Executed successfully in the validation environment · needs BayesFactor

x <- c(4.2,5.1,5.4,4.8,6.0,5.8,4.9,5.6,6.2,5.0)
y <- c(4.0,4.4,4.8,5.0,5.1,4.3,4.7,4.6,5.2,4.9)
print(BayesFactor::ttestBF(x=x,y=y,paired=FALSE,rscale="medium"))
Output
Bayes factor analysis
--------------
[1] Alt., r=0.707 : 3.525677 ±0%

Against denominator:
  Null, mu1-mu2 = 0 
---
Bayes factor type: BFindepSample, JZS

Sources

Statistics guide v4 (historical):
Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 311, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT311.