Skip to content

BCompare groups · Guide test 167

Energy multivariate normality test

Compares observed multivariate data with normality through an energy distance statistic.

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 normality tests, choose Test = Energy.

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 · Energy multivariate normality test

40
0.50
0.60

0 is symmetric.

1.00

Below 1: heavier tails than normal.

0.050

Your data

Simulated with a known ρ

If H₀ were true

E = 1.59
  1. The reference: how E varies across samples when H₀ is true, energy statistic of n = 40 bivariate normal points (Monte Carlo null: 999 samples simulated under H₀ (seed 20261107)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .001).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

E=n[2n∑iE∥yi−Z∥−E∥Z−Z′∥−1n2∑i,j∥yi−yj∥]\mathcal E = n\Bigl[\tfrac{2}{n}\sum_i \mathbb E\|y_i - Z\| - \mathbb E\|Z - Z'\| - \tfrac{1}{n^2}\sum_{i,j}\|y_i - y_j\|\Bigr]

With your numbers

E=1.59,n=40\mathcal E = 1.59,\qquad n = 40
yiy_i
data standardized by the sample covariance
Z,Z′Z, Z'
independent standard normal vectors
E∥y−Z∥\mathbb E\|y - Z\|
expected distance to a normal point (closed form)

The verdict

E = 1.59, p = .001

p ≤ α = .050: reject H₀

The null is simulated from normal samples of the same size, standardized the same way. Energy tests are consistent against every alternative.

Statistic
1.595
p-value
0.0010
Energy multivariate normality test on 40 (x, y) pairs: E = 1.59, p = .001. The p-value is below α = .050, so the data are hard to reconcile with H0.

Energy multivariate normality test on 40 (x, y) pairs: E = 1.59, p = .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: multivariate normality.

Assumptions

Independent identically distributed p-dimensional observations; positive definite covariance and sufficient n relative to p. The null is a multivariate normal distribution with unknown mean/covariance.

Formula

En=n[2n∑iE∥Yi−Z∥−E∥Z−Z′∥−1n2∑ij∥Yi−Yj∥]E_n=n\left[\frac2n\sum_iE\|Y_i-Z\|-E\|Z-Z^\prime\|-\frac1{n^2}\sum_{ij}\|Y_i-Y_j\|\right]

Parameters and notation

Yi=Sn⁻¹ᐟ²(xi−x̄); Z,Z′ are independent Np(0,I). Expectations can be computed analytically/numerically; E‖Z−Z′‖=2Γ((p+1)/2)/Γ(p/2).

Structure of the method

Whiten the observations and compare their pairwise Euclidean distances with distances expected under a standard multivariate normal reference. The energy expression balances observed-to-reference and within-distribution distances. Calibration generates normal datasets rather than treating the statistic as an ordinary chi-square value.

Estimated and nuisance parameters

The sample mean and covariance are nuisance estimates used in standardization. Pairwise distance averages estimate distributional discrepancies; dimension and sample size enter expected normal distances. No classifier or neural embedding is fitted by the classical procedure.

Settings and design choices

Fix covariance normalization, numerical evaluation of normal-distance expectations, bootstrap replication count, random seed, and handling of singular/missing data. The official energy documentation lists mvnorm.test and the older mvnorm.etest alias; record the installed version rather than assuming naming proves a different test.

Fitting and adaptation

Refit the standardization inside every normal-bootstrap replicate. If the observations are model residuals, simulate and refit the producing model where required. Learned feature transformations and robust covariance substitutions need separately justified calibration; they do not automatically preserve the supplied null distribution.

Sensitivity and robustness

A small number of extreme distances can affect the result, and near-singular covariance undermines whitening. Pairwise work has quadratic storage/time considerations unless carefully implemented. Missing values and repeated dependent rows require explicit treatment. Use Monte Carlo uncertainty near decision thresholds and report the statistic, p-value, number of replicates, and relevant distributional plots.

How to use and calibrate

Large En rejects; simulate normal samples and restandardize each to obtain the null reference.

Example application

Check multivariate normality using distances rather than only moments.

Interpretation and pitfalls

Watch out

Whitening requires a stable covariance estimate. A generalized inverse in high dimension does not automatically preserve the standard null calibration.

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

Energy multivariate-normality test with Monte Carlo reference; it fits mean/covariance rather than testing a fixed standard normal distribution.

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)
print(energy::mvnorm.etest(X,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)
print(energy::mvnorm.etest(X,R=999))
Output
	Energy test of multivariate normality: estimated parameters

data:  x, sample size 40, dimension 3, replicates 999
E-statistic = 0.8039, p-value = 0.5325

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