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

diptest can be installed from PyPi using:

    pip install diptest

Wheels containing the pre-compiled extension are available for:

  • Windows x84-64 - CPython 3.7 - 3.10
  • Linux x84-64 - CPython 3.7 - 3.10
  • MacOS x84-64 - CPython 3.7 - 3.10
  • MacOS ARM-64 - CPython 3.8 - 3.10

If you have a C/C++ compiler available it is advised to install without the wheel as this enables architecture specific optimisations.

    pip install diptest --no-binary diptest

Compatible 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 newer
  • Microsoft Visual Studio 2015 Update 3 or newer
  • Intel 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 OpenMP

To enable OpenMP use:

    CMAKE_ARGS="-DDIPTEST_ENABLE_OPENMP=ON" pip install diptest --no-binary diptest

Debug installation

To enable a debug build use:

    CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Debug" pip install diptest --no-binary diptest

Debug printing

To enable the debug print statements use:

    CMAKE_ARGS="-DDIPTEST_ENABLE_DEBUG=ON" pip install diptest --no-binary diptest

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.

    import numpy as np
    import diptest

    # generate some bimodal random draws
    N = 1000
    hN = N // 2
    x = 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 statistic
    dip = diptest.dipstat(x)
    
    # both the dip statistic and p-value
    dip, pval = diptest.diptest(x)

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.2.tar.gz (60.4 kB view details)

Uploaded Source

Built Distributions

diptest-0.2.2-cp310-cp310-win_amd64.whl (96.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

diptest-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (116.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

diptest-0.2.2-cp310-cp310-macosx_11_0_arm64.whl (86.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

diptest-0.2.2-cp310-cp310-macosx_10_13_x86_64.whl (90.0 kB view details)

Uploaded CPython 3.10 macOS 10.13+ x86-64

diptest-0.2.2-cp39-cp39-win_amd64.whl (96.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

diptest-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (116.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

diptest-0.2.2-cp39-cp39-macosx_11_0_arm64.whl (86.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

diptest-0.2.2-cp39-cp39-macosx_10_13_x86_64.whl (90.0 kB view details)

Uploaded CPython 3.9 macOS 10.13+ x86-64

diptest-0.2.2-cp38-cp38-win_amd64.whl (96.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

diptest-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

diptest-0.2.2-cp38-cp38-macosx_11_0_arm64.whl (86.2 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

diptest-0.2.2-cp38-cp38-macosx_10_13_x86_64.whl (90.0 kB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

diptest-0.2.2-cp37-cp37m-win_amd64.whl (97.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

diptest-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.4 kB view details)

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

diptest-0.2.2-cp37-cp37m-macosx_10_13_x86_64.whl (89.5 kB view details)

Uploaded CPython 3.7m macOS 10.13+ x86-64

File details

Details for the file diptest-0.2.2.tar.gz.

File metadata

  • Download URL: diptest-0.2.2.tar.gz
  • Upload date:
  • Size: 60.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for diptest-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0ead0e19248297f7e8ec90ecd0e1bd6df27588a15be87ef66d2cce0eefdae850
MD5 b384842f1155c0532714a68c3bb4ed0c
BLAKE2b-256 e5210c4257427acf14d914123f24aa44db66cfff644a1e7905e2d9b4b134fc05

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: diptest-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 96.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for diptest-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 98572e7a7db56da005d490233a887f2577e7ef07e7076896b9aa64fd7c830bb8
MD5 9240781ee2a0ffad31286a803b10d163
BLAKE2b-256 9cbc1b0d08dbf957b3558cbc5613b18627a50e424d68c3ec51063d2d47c82f2f

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9736bb501a8871ea1156074913014ecdd676347272e374b0338f8a22804ef511
MD5 ca92ff05d19e1d9b323dc6afa61bd466
BLAKE2b-256 d683c826c2142ea3c3b10c1171be10f88514916447f329289240982ae2673528

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48c0bca6c2f47e5aa6993064323ad895a581e636525ca7e498a87a32c897ef70
MD5 c2e5faefa89bfaa32589ef753a62a210
BLAKE2b-256 7011fd1db643dc3922db4b5ff92eef98982737777d4fc940dbd9d249d031ef02

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp310-cp310-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e7213f99fa0983965fd320a67f7ca6447489da628e7cca28418a8dd19e231c65
MD5 036748bafc1b30bd659db35bca3ea1fa
BLAKE2b-256 2791e01e8559f094a47dd5d5aa08b0ecb9abd45410bd28a1ede02b3018315fe7

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: diptest-0.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 96.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for diptest-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 62c30c343c3208afed2524571e339ef6cf0e3420bde62dc781d199dd1b340f03
MD5 62f5468968733dba7cb7848ac728aa67
BLAKE2b-256 975ef80df4a64b1f59b4b30040536214d86c5e7136e8216d878bcd1d38daa810

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2962ecc67a945727dcd4ba7b18f4def541eb7cd640df21c4fdb7ef30e1547393
MD5 59e0f23019c3f686526661d16241fe37
BLAKE2b-256 cce98484b1bf56a0be457c0832290b33ecb1e8e9dfae09b2e2f25a3f74975e60

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef49eca09c3f0b26fd5001db835693ba43fc70411897b4c1dd11f1e35140b5fa
MD5 101064283258390ab32aac22bbb6742e
BLAKE2b-256 c385f2a5495266c1a5343c54f3f9a218f1ac8fa72cb81f7571359db9be462db6

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp39-cp39-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 656b2e119f3d0f3b06c46abe91de2ee3ffd70ce6665bf8cf217a361b43e42dc0
MD5 a1a38d83cbf975aeb47e7f7f9db3c166
BLAKE2b-256 f570aad7dd392cc37d8a10401437012fcb4a0e1bc339042038baf3dbedea95e9

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: diptest-0.2.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 96.8 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for diptest-0.2.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ebc0256224c43891e1df7dff892f95058b7123e91251ae2aacc9f4c8839ef979
MD5 8f8b9682836f9f88ab5efa8a73a152a6
BLAKE2b-256 a5c2e9853bf39b46b7b66113a544df9d916fb836d56eb8260f91281db66276f2

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53ebc5f43521e4d0063374ec38a006c3beb6a2d9c1c1bf98feba5b13f4f644ea
MD5 feb9b2278c8f3fc2e796d2dfb3bb861a
BLAKE2b-256 887a740a751c4680d1cf399b2f27b058322dfae3dc60ab0c55af7b25125061b7

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 038173af53a467ae89c89b4c748f8a15ce621061555c116ffcba24578fd5b69e
MD5 87675d331c82280c111c1caa9e3a6a5d
BLAKE2b-256 f5bd0d1d4fde10f3acf6520ff480b21dd4747b38802e39d0429ac360be99881a

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 f203e180fd9f0109b76517bb77b4697ca6a8673bced539f4c2f0693bf20680af
MD5 8e7e1ec3a6d4849b72ba10b1788d9c8e
BLAKE2b-256 86b4954f093f6d47a1e55d462e4a686885cf5bcb3bf18cc2acdf7861974c1723

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: diptest-0.2.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 97.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for diptest-0.2.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 644d8543e619543cf7e4655001dad3f3fa78a9cb8022e7ee65b4bc1e5695ae3b
MD5 4ec8c842b766175a54420bb5d85a97d4
BLAKE2b-256 4847413a1a887bc7823c33ac7ebafcf245cf1c342512117ae4fcfb8747eb5388

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a50b4ab0aeec3b76e8a18ae75e1ec9f57e0779911e77564fc839174c25e6093b
MD5 05be97bdc28584a7d532ee094c161488
BLAKE2b-256 af4841ff23e54d581222531cb247910dac4b24bfa59eabe3989971728c92574c

See more details on using hashes here.

File details

Details for the file diptest-0.2.2-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.2.2-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4827086bfa384d69e8f6445914175f11c8ffad0353bfaafc3dd1cec9835928dd
MD5 8317cd877cb6d515563e8c79533b9136
BLAKE2b-256 6dc881c33b1944ee8589e3e1972f59197c1636402ad0a74d6178a15c0a45d962

See more details on using hashes here.

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