Skip to content

BCompare groups · Guide test 174

DISCO test

Uses distance components to test distributional differences among multiple groups.

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 Multivariate tests of equal distributions (energy, MMD, DISCO, classifier), choose Test = DISCO.

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 · DISCO test

3
12
0.50
0.20
0.40
1.00

Above 1 the later groups are more spread out (unequal covariance matrices).

0.050

Your data

Simulated with known truth

3 groups on two measurements; crosses mark the group means.

If H₀ were true

F = 1.27
  1. The reference: how F varies across samples when H₀ is true, DISCO F over relabelings (permutation null: 199 relabelings of these data (seed 20261107)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .200).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

F=(T−W)/(k−1)W/(N−k),T=12N∑i,jdij,W=∑g12ng∑i,j∈gdijF = \dfrac{(T - W)/(k-1)}{W/(N-k)},\quad T = \tfrac{1}{2N}\sum_{i,j}d_{ij},\quad W = \sum_g \tfrac{1}{2n_g}\sum_{i,j\in g}d_{ij}

With your numbers

F=1.27,k=3, N=36F = 1.27,\qquad k = 3,\ N = 36
dijd_{ij}
Euclidean distance (index 1)
T,WT, W
total and within-group dispersion

The verdict

F = 1.27, p = .200

p > α = .050: compatible with H₀

With squared distances (index 2) DISCO is ordinary ANOVA; with index 1 it detects any difference in distribution.

Statistic
1.265
p-value
0.2000
DISCO test on 3 groups of 12 rows on two variables: F = 1.27, p = .200. The p-value is above α = .050, so the data are compatible with H0.

DISCO test on 3 groups of 12 rows on two variables: F = 1.27, p = .200. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: all group distributions are identical for 0<α<2; α=2 targets means.

Assumptions

Independent samples; finite αth distance moments and valid group permutation design.

Formula

Tα=12N∑ij∥xi−xj∥αWα=∑g12ng∑i,j∈g∥xi−xj∥αFα=(Tα−Wα)/(k−1)Wα/(N−k)\begin{gathered}T_\alpha=\frac1{2N}\sum_{ij}\|x_i-x_j\|^\alpha\\[5pt] W_\alpha=\sum_g\frac1{2n_g}\sum_{i,j\in g}\|x_i-x_j\|^\alpha\\[5pt] F_\alpha=\frac{(T_\alpha-W_\alpha)/(k-1)}{W_\alpha/(N-k)}\end{gathered}

Parameters and notation

α is a prespecified distance exponent. Between dispersion Sα=Tα−Wα.

Structure of the method

Raise Euclidean distances to the selected exponent, decompose total dispersion into within-group and between-group components, and form either the between statistic or a pseudo-F ratio. This mirrors ANOVA algebra while permitting distribution-sensitive distances. Permutation calibration remains part of the test rather than following from the ratio's name.

Estimated and nuisance parameters

Pairwise powered-distance averages and group dispersion components are estimated. No Gaussian means or variances are required in the basic distance calculation. The distance exponent and choice of between-component versus ratio statistic define the procedure rather than being fitted neural parameters.

Settings and design choices

Fix exponent in the documented range, group factors, scaling, statistic variant, permutation restrictions, and replication count. For exponents below two, equal means alone do not characterize the null; at two, the statistic's mean-focused sensitivity differs even if the permutation null still uses exchangeability.

Fitting and adaptation

Build the one-way decomposition supported by the selected implementation and recompute group-dependent terms under permitted relabelings. More complicated designs require a justified extension rather than assuming a familiar formula interface supplies it. Learned transformations or data-driven exponent selection must be isolated or incorporated into calibration.

Sensitivity and robustness

Exponent choice controls tail influence and sensitivity to shape versus mean changes. At exponent two, general same-mean alternatives can escape detection; unequal-variance mean-only nulls do not automatically justify unrestricted permutations. Sparse groups, dependence, high-dimensional distances, and numerical cancellation affect results. State the exact hypothesis and implemented statistic alongside the decomposition.

How to use and calibrate

Use label permutation for the F ratio or between-dispersion statistic. At α=2 the decomposition matches ordinary squared Euclidean ANOVA.

Example application

Analyze distributional group differences through an energy-distance ANOVA decomposition.

Interpretation and pitfalls

Watch out

α changes the hypothesis sensitivity; α=2 loses general consistency against same-mean alternatives.

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

Euclidean distance, independent groups, 999 unrestricted permutations. Clustered or repeated designs require restricted permutations; location and dispersion can affect different procedures.

Python · invokes R

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

# 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"""
set.seed(2026)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
Z<-rbind(X,Y);g<-factor(rep(1:2,c(nrow(X),nrow(Y))))
print(energy::disco(Z,factors=g,R=999))
"""
# 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 energy

set.seed(2026)
X<-matrix(rnorm(120),ncol=3);Y<-matrix(rnorm(150,mean=.3),ncol=3)
Z<-rbind(X,Y);g<-factor(rep(1:2,c(nrow(X),nrow(Y))))
print(energy::disco(Z,factors=g,R=999))
Output
energy::disco(x = Z, factors = g, R = 999)

Distance Components: index  1.00
Source            Df   Sum Dist  Mean Dist   F-ratio   p-value
factors            1    4.82097    4.82097     4.430     0.001
Within            88   95.76404    1.08823
Total             89  100.58501

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