Skip to main content

Hartigan's diptest.

Project description

diptest

Linux Build Windows Build MacOS build

A 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.

Dependencies

  • numpy
  • [Optional] OpenMP

Parallelisation 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 of diptest for details.

Installation

    cd diptest
    pip install .

Enable OpenMP

To enable OpenMP use:

    SKBUILD_CONFIGURE_OPTIONS="-DDIPTEST_ENABLE_OPENMP=ON" pip3 install . -v

Debug installation

To enable a debug build use:

    SKBUILD_CONFIGURE_OPTIONS="-DCMAKE_BUILD_TYPE=Debug" pip3 install . -v

Debug printing

To enable the debug print statements use:

    SKBUILD_CONFIGURE_OPTIONS="-DDIPTEST_ENABLE_DEBUG=ON" pip3 install . -v

then call the function with debug argument set to a value greater than zero:

    diptest(x, debug=1)

Usage

This library provides two functions:

  • dipstat
  • diptest

The first only computes Hartigan's dip statistic. diptest computes 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.

References

Hartigan, 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.

Acknowledgement

diptest is just a Python port of Martin Maechler's R module of the same name. The package wrapping the C implementation was originally written by Alistair Muldal. The fork is an update with a number of changes:

  • Fixes a buffer overrun issue in _dip.c by reverting to the original C implementation
  • Python bindings using Pybind11 (C++) instead of Cython
  • P-value computation using bootstrapping has been moved down to C++ with optional parallelisation support through OpenMP
  • Removed overhead caused by debug branching statements by placing them under a compile-time definition
  • Added tests and wheel support

License

diptest is 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diptest-0.2.0.tar.gz (56.7 kB view hashes)

Uploaded Source

Built Distributions

diptest-0.2.0-cp310-cp310-win_amd64.whl (96.2 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

diptest-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115.1 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

diptest-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (85.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

diptest-0.2.0-cp310-cp310-macosx_10_13_x86_64.whl (89.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.13+ x86-64

diptest-0.2.0-cp39-cp39-win_amd64.whl (95.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

diptest-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

diptest-0.2.0-cp39-cp39-macosx_11_0_arm64.whl (85.5 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

diptest-0.2.0-cp39-cp39-macosx_10_13_x86_64.whl (89.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.13+ x86-64

diptest-0.2.0-cp38-cp38-win_amd64.whl (96.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

diptest-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

diptest-0.2.0-cp38-cp38-macosx_11_0_arm64.whl (85.4 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

diptest-0.2.0-cp38-cp38-macosx_10_13_x86_64.whl (89.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.13+ x86-64

diptest-0.2.0-cp37-cp37m-win_amd64.whl (96.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

diptest-0.2.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (116.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

diptest-0.2.0-cp37-cp37m-macosx_10_13_x86_64.whl (88.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.13+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page