Skip to content

CAssociation · Guide test 084

Hoeffding D test

Detects departures from independence using a rank based dependence 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 Test for any dependence (ξ, Hoeffding, distance correlation, HSIC), choose Dependence measure = Hoeffding's D.

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 · Hoeffding D test

30

Shape of the link

0.80
0.050

Your data

Simulated with a known link

If H₀ were true

D = 0.0018
  1. The reference: how D varies across samples when H₀ is true, 999 permutations of y (permutation null on the shared Wichmann–Hill stream).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .024).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

D=Q−2(n−2)R+(n−2)(n−3)Sn(n−1)(n−2)(n−3)(n−4)D=\dfrac{Q-2(n-2)R+(n-2)(n-3)S}{n(n-1)(n-2)(n-3)(n-4)}

With your numbers

D=0.0018,30D=0.0018D = 0.0018,\qquad 30D = 0.0018
Q, R, SQ,\ R,\ S
rank sums built from bivariate counts
30D30D
the scale Hmisc reports

The verdict

D = 0.0018, p = .024, 30D = 0.05

p ≤ α = .050: reject H₀

Effect size: Hoeffding's D on Hmisc's scale 30D = 0.053

A rank measure of departure from independence that also sees non-monotone shapes. The p-value permutes y on the shared stream.

Statistic
0.002
p-value
0.0240
Hoeffding D test on 30 (x, y) pairs: D = 0.0018, p = .024, 30D = 0.05. The p-value is below α = .050, so the data are hard to reconcile with H0.

Hoeffding D test on 30 (x, y) pairs: D = 0.0018, p = .024, 30D = 0.05. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: X and Y are independent.

Assumptions

Independent paired observations; the simple formula assumes continuous margins and n≥5; tie corrections extend it.

Formula

D=Q−2(n−2)R+(n−2)(n−3)Sn(n−1)(n−2)(n−3)(n−4)D=\frac{Q-2(n-2)R+(n-2)(n-3)S}{n(n-1)(n-2)(n-3)(n-4)}

Parameters and notation

Let ai,bi be marginal ranks and ci=number of other observations smaller in both coordinates. Q=Σ(ai−1)(ai−2)(bi−1)(bi−2); R=Σ(ai−2)(bi−2)ci; S=Σci(ci−1). Some software reports 30D.

Structure of the method

Compute marginal ranks and bivariate dominance counts, combine them into Hoeffding’s U-statistic, and calibrate against a stated independence reference. The statistic compares empirical joint structure with a product-of-marginals structure and can detect some nonmonotonic patterns missed by ordinary correlation.

Estimated and nuisance parameters

Marginal ranks, bivariate ranks, and the dependence coefficient are empirical quantities; no parametric marginal distribution is fitted. The original D and the commonly reported 30D differ only by scale, but the statistic must be matched to its critical-value or p-value calculation.

Settings and design choices

Choose tie handling, complete-pair deletion, asymptotic-table versus permutation calibration, and permutation count. The Hmisc route reports a scaled coefficient and an approximate p-value, not a finite-sample permutation p-value. For a matrix of variables, define a multiplicity family before screening.

Fitting and adaptation

Recompute dominance counts when observations or ties change. Under an independence permutation, shuffle the pairing while preserving both marginal samples and recalculate the same rank convention. No fine-tuning stage exists. Missing-data handling should keep each reported test’s effective sample size visible.

Sensitivity and robustness

At least five usable pairs are needed for the displayed denominator, but that minimum is not a guarantee of accurate asymptotic inference. Ties and discrete margins need special care. Negative finite-sample estimates are possible and should not be truncated before calibrating unless the method explicitly requires it.

How to use and calibrate

Use permutation or a documented asymptotic null distribution. Large D suggests dependence, including nonlinear patterns.

Example application

Detect a nonlinear association missed by Pearson correlation.

Interpretation and pitfalls

Watch out

Finite sample D can be negative. Scale conventions and tie handling must match the 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

The output contains Hoeffding D and its approximate p-value; Hmisc scales D so that its convention differs from some original-statistic implementations.

Python · invokes R

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

# 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(Hmisc::hoeffd(cbind(x,y)))
"""
# 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 Hmisc

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(Hmisc::hoeffd(cbind(x,y)))
Output
D
      x     y
x  1.00 -0.13
y -0.13  1.00

avg|F(x,y)-G(x)H(y)|
      x     y
x 0.000 0.044
y 0.044 0.000

max|F(x,y)-G(x)H(y)|
     x    y
x 0.00 0.09
y 0.09 0.00

n= 10 

P
  x  y 
x     1
y  1

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