Skip to content

BCompare groups · Guide test 312

Jeffreys Bayesian correlation test

Compares a zero correlation model with a prior distributed nonzero correlation model.

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:

In Bayesian correlation (Jeffreys Bayes factor), choose Prior width on ρ = Ultrawide (κ = 1, uniform).

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 Bayesian correlation test

30
0.40
1.00

Stretched Beta(1/κ, 1/κ) on ρ: κ = 1 is uniform on (−1, 1) (ultrawide), 1/3 medium.

0.050

Your data

Simulated with a known ρ

If H₀ were true

t = 0.61
  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 = .546).
  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.27: moderate evidence for H₀ (prior: stretched Beta(1, 1) 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=2(κ−2)/κπB(1κ,1κ) Γ(n+2/κ−12)Γ(n+2/κ2)  2F1 ⁣(n−12,n−12;n+2/κ2;r2)\mathrm{BF}_{10}=\frac{2^{(\kappa-2)/\kappa}\sqrt\pi}{B(\tfrac1\kappa,\tfrac1\kappa)}\,\frac{\Gamma(\frac{n+2/\kappa-1}{2})}{\Gamma(\frac{n+2/\kappa}{2})}\;{}_2F_1\!\Big(\tfrac{n-1}2,\tfrac{n-1}2;\tfrac{n+2/\kappa}2;r^2\Big)

With your numbers

r=0.11, n=30, κ=1 ⇒ BF10=0.27r = 0.11,\ n = 30,\ \kappa = 1\ \Rightarrow\ \mathrm{BF}_{10} = 0.27
κ\kappa
prior width: a stretched Beta(1/κ, 1/κ) on ρ; κ = 1 is uniform on (−1, 1)
2F1{}_2F_1
Gauss' hypergeometric function (Ly, Verhagen & Wagenmakers 2016)

The verdict

t(28) = 0.61, p = .546, BF₁₀ = 0.27

p > α = .050: compatible with H₀

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

The prior on ρ is part of the question: a wide prior spreads belief over large correlations and so favors H0 more readily for small ones.

Statistic
0.611
p-value
0.5463
Jeffreys Bayesian correlation test on 30 (x, y) pairs: t(28) = 0.61, p = .546, BF10 = 0.27. The p-value is above α = .050, so the data are compatible with H0.

Jeffreys Bayesian correlation test on 30 (x, y) pairs: t(28) = 0.61, p = .546, BF₁₀ = 0.27. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: population Pearson correlation ρ=0; H1: ρ follows a specified prior on (−1,1).

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. Independent bivariate normal observations and compatible nuisance priors for means/scales.

Formula

BF10=∫−11m(D∣ρ)π(ρ) dρm(D∣ρ=0)π(ρ)=(1+ρ)a−1(1−ρ)a−122a−1B(a,a)\begin{gathered}BF_{10}=\frac{\int_{-1}^{1}m(D\mid\rho)\pi(\rho)\,d\rho}{m(D\mid\rho=0)}\\[5pt]\pi(\rho)=\frac{(1+\rho)^{a-1}(1-\rho)^{a-1}}{2^{2a-1}B(a,a)}\end{gathered}

Parameters and notation

m(D|ρ) is the bivariate-normal likelihood integrated over the stated common nuisance priors. a=1/rscale gives the shifted Beta(a,a) prior; rscale=1 is uniform, while BayesFactor’s medium setting is 1/3.

Structure of the method

Integrate the bivariate-normal likelihood over a specified prior on correlation and compatible nuisance means/scales, then compare with the marginal likelihood at zero correlation. The BayesFactor implementation uses a shifted symmetric beta prior parameterized by rscale, yielding a family of evidence calculations.

Estimated and nuisance parameters

Correlation and nuisance location/scale parameters are integrated model quantities. The sample Pearson correlation and n summarize relevant data information under the model. rscale controls the prior with shape a=1/rscale; rscale=1 gives a uniform correlation prior, whereas the package medium setting is narrower.

Settings and design choices

Prespecify prior width, zero or interval/directional hypothesis, model odds if posterior probabilities are desired and missing-data handling. A prior on correlation is not equivalent to placing an arbitrary normal prior on Fisher’s transformed correlation without the Jacobian and likelihood implications.

Fitting and adaptation

Fit/integrate the declared Bayesian model and inspect numerical accuracy. Compare a planned range of plausible prior widths to show robustness; choosing the most favorable width after analysis is not neutral tuning. For nonlinear, heavy-tailed or clustered relationships, specify a different model rather than claiming this test is distribution-free.

Sensitivity and robustness

Restricted range, influential points and nonnormality can strongly alter correlation evidence. A near-zero Pearson correlation does not imply independence, and support for zero under one prior is relative model evidence. Report sample size, scatterplot, posterior summaries where useful, Bayes-factor orientation and prior assumptions.

How to use and calibrate

Use the Jeffreys-based integrated correlation method, reporting prior width, direction restrictions and BF orientation.

Example application

Compare evidence for zero versus nonzero linear correlation.

Interpretation and pitfalls

Watch out

Uniform and narrower correlation priors give different evidence. Posterior probability of H0 additionally requires prior model odds.

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

Jeffreys correlation Bayes factor with rscale=1; state the prior and BF direction. Posterior probability requires prior model odds.

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::correlationBF(x,y,rscale=1))
"""
# 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::correlationBF(x,y,rscale=1))
Output
Bayes factor analysis
--------------
[1] Alt., r=1 : 1.209143 ±0%

Against denominator:
  Null, rho = 0 
---
Bayes factor type: BFcorrelation, Jeffreys-beta*

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 312, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT312.