Statistical Foundations
Energy Distance and Distance Covariance
Compare distributions and test independence using pairwise distances: population energy distance, biased and unbiased estimators, permutation tests, distance covariance, MMD equivalence, and the proper energy score.
Prerequisites
Learning position
Read this page in the graph.
statistical-foundations | layer 3 | tier 2. This page has 3 direct prerequisites and 0 published dependents.
What next
Take the diagnosticNo published continuation is declared yet, so the diagnostic is the clean next route.
Evidence badge
Claim statusThis page has no public Lean mapping yet. Use the evidence page to inspect how claim status labels work.
Why This Matters
Means and covariances can agree while distributions differ. Pearson correlation can be zero while variables remain strongly dependent. Energy statistics address both problems using pairwise distances:
- energy distance measures whether two probability distributions differ;
- distance covariance measures whether two random vectors are dependent;
- permutation tests turn both quantities into finite-sample tests under exchangeability;
- distance-induced kernels connect energy distance to maximum mean discrepancy (MMD);
- the same population discrepancy yields a strictly proper multivariate forecast score.
This use of energy is separate from energy-based models. There is no learned energy landscape or partition function here. See Energy in Statistics and Machine Learning for the terminology map.
Mental Model
Pool two samples and inspect all pairwise distances.
- If the samples come from the same distribution, a cross-sample pair should look much like a within-sample pair.
- If the distributions differ, cross-sample distances tend to be larger than the within-sample distances after the comparison is centered correctly.
Energy distance is twice the average cross-distance minus the two average within-distances. Distance covariance applies a related idea to paired data: center the distance matrix for , center the distance matrix for , then measure whether large and small distances align across the two matrices.
Population Energy Distance
Let be a space with a symmetric nonnegative semimetric satisfying . Let
with all four variables mutually independent.
Energy Distance
Under the convention used on this page, the squared-form energy distance is
This page follows the common Székely-Rizzo statistical convention and calls the energy distance. Some metric treatments instead apply the name to . Always check the convention. For Euclidean energy distance, rather than squared Euclidean distance.
The expectations are finite when and have finite first -moments, meaning for some .
Energy Distance Characterizes Equality of Distributions
Statement
Euclidean distance on is of strong negative type, so the result holds for random vectors with finite first moments.
Intuition
The cross-distance term is compared with the natural within-distribution spread of each law. Strong negative type says that this centered comparison separates probability measures, not merely individual points.
Proof Sketch
Negative type gives a Hilbert-space embedding such that . Expanding the three expectations gives
This is nonnegative. Strong negative type makes the mean embedding injective on probability measures with finite first moments, giving the equality claim.
Why It Matters
Energy distance detects any distributional difference allowed by the assumptions, not only a change in mean or covariance. It supplies a nonparametric two-sample target without density estimation.
Failure Mode
Negative type alone gives nonnegativity but may not make zero identify the distribution. Without finite moments, one or more expectations can be infinite. Replacing with an arbitrary dissimilarity can invalidate both conclusions.
Two point masses
Let and on . Then , while both within-distribution expectations are zero. Hence
The discrepancy increases with separation, even though neither distribution has within-sample spread.
Sample Estimators
Given independent observations and , define pairwise distances , , and .
Biased V-statistic
The plug-in estimator is
For a negative-type semimetric this estimator is nonnegative. It is biased because empirical within-sample expectations include diagonal pairs, although for ordinary distances.
Unbiased U-statistic
Removing diagonal pairs and changing the denominators gives
This estimator is unbiased for when . Unlike the population distance and the biased estimator, it can be negative in a finite sample. That is not a contradiction: unbiasedness does not impose the range of the estimand on every realization.
Biased does not mean invalid
The nonnegative V-statistic and the unbiased U-statistic answer slightly different finite-sample needs. Either can be used as an ordering statistic in a correctly constructed permutation test. Do not truncate a negative U-statistic to zero unless the chosen method explicitly calls for that transformation.
The Two-Sample Permutation Test
To test against :
- Compute on the observed group labels.
- Pool all observations.
- Reassign observations to the first group and to the second.
- Recompute the statistic for each reassignment, or for a random set of reassignments.
- Reject for an unusually large observed statistic.
Under , the pooled observations are exchangeable with respect to the group labels. Enumerating every label allocation gives a conditional test of level at most , with randomized boundary handling available for exact size. For random permutations, use the corrected one-sided value
The correction prevents a zero Monte Carlo p-value and preserves finite- validity under the standard exchangeability construction. See Permutation Tests for the general argument.
Exchangeability is the load-bearing assumption
Independent samples from the same distribution satisfy the usual two-sample null. Clustered data, time series, matched pairs, and covariate-dependent assignment may not permit unrestricted label shuffling. Use a permutation scheme that respects the design, or use a method derived for that dependence structure.
Equivalence to Maximum Mean Discrepancy
Energy distance and kernel MMD can be two coordinate systems for the same population discrepancy.
For a semimetric of negative type and a fixed base point , define the distance-induced kernel
Changing changes the kernel representation but not the MMD between probability measures.
Energy Distance Equals Twice Squared MMD
Statement
If is of strong negative type, the associated mean embedding is injective on the relevant probability measures, matching the property.
Intuition
Both quantities compare a cross expectation with two within-distribution expectations. Substituting the distance generated by makes the marginal terms cancel, leaving the same centered discrepancy up to a factor of two.
Proof Sketch
Start from
Replace each in by . All diagonal expectation terms cancel, and the remaining expression is twice the displayed MMD quantity.
Why It Matters
Results and implementations can move between distance and kernel language. Choosing a ground semimetric corresponds to choosing a kernel geometry; both choices control test power.
Failure Mode
An arbitrary distance need not generate a positive-definite kernel, and an arbitrary kernel need not be characteristic. The equivalence does not say that every distance test has power against every alternative.
Distance Covariance and Distance Correlation
Energy distance compares two distributions. Distance covariance instead tests whether paired random vectors and are independent.
Given paired observations , form
Double-center both distance matrices:
Here is row 's mean, is column 's mean, and is the grand mean. The usual biased sample squared distance covariance is
For , an unbiased estimator uses U-centering rather than the ordinary double-centering above. For , define
and define analogously. Then
is unbiased for squared population distance covariance. Like the unbiased energy-distance estimator, it can be negative in a finite sample. The ordinary double-centered statistic remains common for permutation testing; the estimator and null calibration should be reported explicitly.
The normalized distance correlation is
when the denominator is positive, and is defined as zero otherwise. For ordinary Euclidean distances, the denominator vanishes when at least one sample has no distance variation, as when every observed value on that side is identical.
Distance Covariance Characterizes Independence
Statement
The population distance covariance satisfies
More generally, the equivalence holds when the marginal spaces are of strong negative type and the required moments exist.
Intuition
If two observations are far apart in whenever they are far apart in , the centered distance matrices align. Independence removes this systematic alignment. Strong negative type prevents a dependent joint law from having the same embedding as the product of its marginals.
Proof Sketch
In Euclidean spaces, population distance covariance has a weighted characteristic-function representation:
The nonnegative integral is zero exactly when the joint characteristic function factors everywhere, which is equivalent to independence. The metric space result replaces characteristic functions with injective distance or kernel embeddings.
Why It Matters
Ordinary covariance detects linear association. At the population level, distance covariance separates independence from dependence under its assumptions while remaining computable from pairwise distances. Finite-sample power still depends on the alternative, dimension, tails, and calibration.
Failure Mode
In a general metric space lacking strong negative type, zero distance covariance need not imply independence. A finite sample value near zero is not itself a calibrated test result; use an appropriate permutation or asymptotic null procedure.
Zero Pearson correlation but perfect dependence
Let be uniform on and let . Symmetry gives , yet is determined by . Population distance covariance is positive because and are not independent.
The Proper Energy Score
Let a forecast distribution be on , let be the realized outcome, and let . For , the energy-score family in loss orientation is
The standard member is
Lower is better. If the true outcome distribution is , then
For , the energy-distance characterization makes the score strictly proper on the finite-first-moment class: the true distribution uniquely minimizes expected loss. This is the multivariate generalization of the continuous ranked probability score, and in one dimension the member equals the CRPS. For general , the corresponding moment condition and energy distance use . This score is not the log-sum-exp OOD score sometimes called classifier energy.
Energy Distance Versus Nearby Methods
| Method | Population target | Sample ingredients | Zero means |
|---|---|---|---|
| Energy distance | centered expected ground distances | all cross and within pairwise distances | under strong negative type |
| MMD | RKHS mean-embedding distance | kernel evaluations | for a characteristic kernel |
| Wasserstein distance | minimum coupling cost | an optimal transport problem | for a valid ground metric |
| Distance covariance | dependence discrepancy | paired, double-centered distance matrices | independence under stated assumptions |
| Pearson correlation | normalized covariance | paired centered products | no linear association, not necessarily independence |
The MMD row can be mathematically equivalent to energy distance after matching the kernel and semimetric. Wasserstein distance is not: it optimizes over couplings rather than averaging independent cross-pairs.
Practical Workflow
For a two-sample analysis:
- State the null as equality of distributions, not merely equality of means.
- Choose a ground semimetric suited to the data and verify its negative-type property if using the general theorem.
- Inspect scale and preprocessing. Euclidean distance can be dominated by high-variance coordinates.
- Choose the U- or V-statistic deliberately.
- Calibrate by a permutation scheme valid for the sampling design.
- Report the statistic, sample sizes, permutation count, p-value convention, and the exact preprocessing.
- Treat rejection as evidence that the distributions differ, not as a diagnosis of how they differ.
For an independence analysis, preserve the pairings and permute one side across pairs only when those permutations are justified by the null and design.
Common Confusions
Energy statistics are not energy-based models
Energy statistics operate on distances among observations. EBMs assign an energy to each configuration and normalize . Their formulas, algorithms, and inferential questions are different.
Squared Euclidean distance is not the standard Euclidean energy distance
The classical formula uses . Using collapses the population expression to a multiple of the squared mean difference, so it no longer detects arbitrary distributional changes.
A significant test does not measure practical importance
With enough data, a small distributional difference can be detected. Report the energy statistic in context, inspect what changed, and avoid interpreting a p-value as an effect size or operational consequence.
Exercises
Problem
Compute when and on the real line using .
Problem
Show that using gives
when second moments exist.
Problem
Explain why a negative value of does not refute the nonnegativity of population energy distance.
Problem
Design a valid permutation test for paired observations using distance covariance. State what is permuted and the null assumption needed.
References
Energy distance and two-sample testing:
- Székely and Rizzo, "Testing for Equal Distributions in High Dimension" (InterStat, 2004), Sections 2 and 3.
- Székely and Rizzo, "Energy Statistics: A Class of Statistics Based on Distances" (Journal of Statistical Planning and Inference, 2013), Sections 2 through 4. DOI: 10.1016/j.jspi.2013.03.018.
- Baringhaus and Franz, "On a New Multivariate Two-Sample Test" (Journal of Multivariate Analysis, 2004), Sections 2 and 3. DOI: 10.1016/S0047-259X(03)00079-4.
Distance covariance and metric spaces:
- Székely, Rizzo, and Bakirov, "Measuring and Testing Dependence by Correlation of Distances" (Annals of Statistics, 2007), Theorems 1 through 3. DOI: 10.1214/009053607000000505.
- Székely and Rizzo, "Brownian Distance Covariance" (Annals of Applied Statistics, 2009), Sections 2 and 3. DOI: 10.1214/09-AOAS312.
- Székely and Rizzo, "Partial Distance Correlation with Methods for Dissimilarities" (Annals of Statistics, 2014), Section 3.1. DOI: 10.1214/14-AOS1255.
- Lyons, "Distance Covariance in Metric Spaces" (Annals of Probability, 2013), Section 3 (strong-negative-type characterization). DOI: 10.1214/12-AOP803.
Kernel equivalence, tests, and scores:
- Sejdinovic, Sriperumbudur, Gretton, and Fukumizu, "Equivalence of Distance-Based and RKHS-Based Statistics in Hypothesis Testing" (Annals of Statistics, 2013), Sections 2, 3, and Theorem 22.
- Gretton, Borgwardt, Rasch, Schölkopf, and Smola, "A Kernel Two-Sample Test" (Journal of Machine Learning Research, 2012), Sections 2 through 6.
- Gneiting and Raftery, "Strictly Proper Scoring Rules, Prediction, and Estimation" (Journal of the American Statistical Association, 2007), Section 4.3. DOI: 10.1198/016214506000001437.
- Phipson and Smyth, "Permutation P-values Should Never Be Zero: Calculating Exact P-values When Permutations Are Randomly Drawn" (Statistical Applications in Genetics and Molecular Biology, 2010), Sections 2 and 3.
Next Topics
- Kernel Two-Sample Tests: the RKHS and MMD formulation of distribution comparison.
- Proper Scoring Rules: why forecast losses should make honest probability reports optimal.
- Wasserstein Distances: comparison through optimal transport rather than independent pairwise distances.
Last reviewed: July 26, 2026
Canonical graph
Required before and derived from this topic
These links come from prerequisite edges in the curriculum graph. Editorial suggestions are shown here only when the target page also cites this page as a prerequisite.
Required prerequisites
3- Expectation, Variance, Covariance, and Momentslayer 0A · tier 1
- Permutation Testslayer 2 · tier 1
- Energy in Statistics and Machine Learninglayer 2 · tier 2
Derived topics
0No published topic currently declares this as a prerequisite.