Skip to content

ADescribe · Guide test 127

Hartigan dip test

Tests unimodality by measuring distance from the closest unimodal distribution function.

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:

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 · Hartigan dip test

80
3.80
0.50
0.050

Your data

A mixture of two normal modes
Sample · n = 80 · mean 0.44

If H₀ were true

D = 0.05
  1. The reference: how D varies across samples when H₀ is true, simulated: 1999 uniform samples of 80 (simulated null (uniform, the least favorable unimodal law)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .268).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

D=inf⁡G unimodal sup⁡x∣Fn(x)−G(x)∣D=\inf_{G\ \text{unimodal}}\ \sup_x\left|F_n(x)-G(x)\right|

With your numbers

D=0.05,n=80D = 0.05,\qquad n = 80
FnF_n
the empirical CDF
GG
the closest unimodal CDF (convex then concave)

The verdict

D = 0.045, p = .268

p > α = .050: compatible with H₀

Effect size: dip D = 0.045

The largest distance to the nearest unimodal distribution. Calibrated against the uniform, the least favorable unimodal law, so it is conservative for peaked unimodal data.

Statistic
0.045
p-value
0.2680
Hartigan dip test on Sample: n = 80: D = 0.045, p = .268. The p-value is above α = .050, so the data are compatible with H0.

Hartigan dip test on Sample: n = 80: D = 0.045, p = .268. The p-value is above α = .050, so the data are compatible with H₀.

Question and hypotheses

H0: the population distribution is unimodal; H1: it is not unimodal.

Assumptions

Independent univariate observations; continuous data for standard calibration.

Formula

Dn=inf⁡G∈Usup⁡x∣Fn(x)−G(x)∣D_n=\inf_{G\in\mathcal U}\sup_x|F_n(x)-G(x)|

Parameters and notation

U is the class of unimodal CDFs. The dip is the smallest sup-norm distance from the empirical CDF to that class.

Structure of the method

Find the smallest maximum distance from the empirical CDF to any unimodal CDF using the greatest-convex-minorant/least-concave-majorant construction. The statistic assesses global departure from unimodality without fitting a finite mixture or selecting a kernel-density bandwidth.

Estimated and nuisance parameters

The empirical CDF and best-fitting unimodal envelope are data-dependent. The number of mixture components is not estimated by the dip test, and the statistic is not a learned clustering assignment.

Settings and design choices

Choose tabulated interpolation versus simulated uniform-reference calibration, replication count and significance level. Do not tune histogram or density bandwidth to the test result and claim that the resulting visible modes are independently confirmed.

Fitting and adaptation

Compute the dip for the observed sample and calibrate against simulated uniform samples of the same size when using that reference. Reapply the same algorithm to new data. This is shape-constrained fitting and null calibration, not neural adaptation. Report the dip, n and calibration method; use separate modeling to estimate modes or mixture components.

Sensitivity and robustness

Uniform-reference calibration is commonly conservative over unimodal distributions. Close or low-mass modes can be hard to detect at small n. Ties, rounding and discrete outcomes require care; rejection does not prove the existence of scientifically distinct latent populations.

How to use and calibrate

Compute via the convex-minorant/concave-majorant algorithm; use tabulated or simulated uniform-null calibration, commonly conservative over unimodal distributions.

Example application

Assess evidence that a measurement distribution contains multiple modes.

Interpretation and pitfalls

Watch out

A nonsignificant dip does not establish one latent population; small samples may lack power for close modes.

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

Dip test of unimodality; uniform-null simulation provides the conventional calibration. Failure to reject does not prove a single parametric component.

Python · invokes R

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

# 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 <- rnorm(60)
print(diptest::dip.test(x,simulate.p.value=TRUE,B=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 diptest

set.seed(2026)
x <- rnorm(60)
print(diptest::dip.test(x,simulate.p.value=TRUE,B=999))
Output
	Hartigans' dip test for unimodality / multimodality with simulated
	p-value (based on 999 replicates)

data:  x
D = 0.032661, p-value = 0.9389
alternative hypothesis: non-unimodal, i.e., at least bimodal

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