Package: diptest
diptestA Python/C(++) implementation of Hartigan & Hartigan's dip test for unimodality.The dip test measures multimodality in a sample by the maximum difference, over
all sample points, between the empirical distribution function, and the
unimodal distribution function that minimizes that maximum difference. Other
than unimodality, it makes no further assumptions about the form of the null
distribution.Dependenciesnumpy[Optional]OpenMPParallelisation of the p-value computation using bootstrapping is offered using OpenMP.
OpenMP is disabled by default but can be enabled, see installation section
below.
Multi-threading can be turned off by setting the number of threads equal to 1. See the docstring ofdiptestfor details.Installationdiptest can be installed from PyPi using:pipinstalldiptestWheels containing the pre-compiled extension are available for:Windows x84-64 - CPython 3.7 - 3.12Linux x84-64 - CPython 3.7 - 3.12MacOS x84-64 - CPython 3.7 - 3.12MacOS ARM-64 - CPython 3.8 - 3.12If you have a C/C++ compiler available it is advised to install without
the wheel as this enables architecture specific optimisations.pipinstalldiptest--no-binarydiptestCompatible compilers through Pybind11:Clang/LLVM 3.3 or newer (for Apple Xcode's clang, this is 5.0.0 or newer)GCC 4.8 or newerMicrosoft Visual Studio 2015 Update 3 or newerIntel classic C++ compiler 18 or newer (ICC 20.2 tested in CI)Cygwin/GCC (previously tested on 2.5.1)NVCC (CUDA 11.0 tested in CI)NVIDIA PGI (20.9 tested in CI)Enable OpenMPTo enable OpenMP use:SKBUILD_CMAKE_ARGS="-DDIPTEST_ENABLE_OPENMP=ON"pipinstalldiptest--no-binarydiptestDebug installationTo enable a debug build use:SKBUILD_CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug"pipinstalldiptest--no-binarydiptestDebug printingTo enable the debug print statements use:SKBUILD_CMAKE_ARGS="-DDIPTEST_ENABLE_DEBUG=ON"pipinstalldiptest--no-binarydiptestthen call the function with debug argument set to a value greater than zero:diptest(x,debug=1)UsageThis library provides two functions:dipstatdiptestThe first only computes Hartigan's dip statistic.diptestcomputes both the
statistic and the p-value. The p-value can be computed using interpolation of a
critical value table (default) or by bootstrapping the null hypothesis.
Note that for larger samples (N > 1e5) this is quite compute and memory intensive.importnumpyasnpimportdiptest# generate some bimodal random drawsN=1000hN=N//2x=np.empty(N,dtype=np.float64)x[:hN]=np.random.normal(0.4,1.0,hN)x[hN:]=np.random.normal(-0.4,1.0,hN)# only the dip statisticdip=diptest.dipstat(x)# both the dip statistic and p-valuedip,pval=diptest.diptest(x)ReferencesHartigan, J. A., & Hartigan, P. M. (1985). The Dip Test of Unimodality. The
Annals of Statistics.Hartigan, P. M. (1985). Computation of the Dip Statistic to Test for
Unimodality. Journal of the Royal Statistical Society. Series C (Applied
Statistics), 34(3), 320-325.Acknowledgementdiptestis just a Python port ofMartin Maechler's R module of the same
name.
The package wrapping the C implementation was originally written byAlistair Muldal.
The fork is an update with a number of changes:Fixes a buffer overrun issue in_dip.cby reverting to the original C implementationPython bindings using Pybind11 (C++) instead of CythonP-value computation using bootstrapping has been moved down to C++ with optional parallelisation support through OpenMPRemoved overhead caused by debug branching statements by placing them under a compile-time definitionAdded tests and wheel supportC implementation of diptest was rewritten in C++ byProdromos KolyvakisLicensediptestis free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.