A Python implementation of the Z-Dip statistic: a sample size-independent standardisation of Hartigan's Dip Test for detecting multimodality.
This package is a Python port of the method and reference implementation described in:
- Edoardo Di Martino, Matteo Cinelli, Roy Cerqueti (2025), Z-Dip: a standardized measure for data modality assessment
- Original R implementation: EdoardoDima/zdip
The lookup table in pzdip/data/null_table.npz is a copy of the lookup table provided with that R package.
The authors mentioned above deserve the entirety of the credit for the methods implemented here.
pip install pzdipBasic usage:
import numpy as np
import pzdip
RNG = np.random.default_rng(0)
def normal(n, loc=0, scale=1):
return RNG.normal(loc, scale, n)
def bimodal(n):
half = n // 2
return np.concatenate([RNG.normal(-3, 0.5, half), RNG.normal(3, 0.5, n - half)])
result_unimodal = pzdip.zdip(normal(100))
print(result_unimodal)
# ZDipResult(zdip=-0.7204, dip=0.031006, n=100, multimodal=False)
result_bimodal = pzdip.zdip(bimodal(100))
print(result_bimodal)
#ZDipResult(zdip=16.8099, dip=0.169151, n=100, multimodal=True)MIT, see LICENSE. This is an independent Python reimplementation; credit to Edoardo Di Martino and coauthors for the original method and R package.