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
  • C implementation of diptest was rewritten in C++ by Prodromos Kolyvakis

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

Uploaded Source

Built Distributions

diptest-0.5.0-cp310-cp310-win_amd64.whl (98.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

diptest-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

diptest-0.5.0-cp310-cp310-macosx_11_0_arm64.whl (87.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

diptest-0.5.0-cp310-cp310-macosx_10_13_x86_64.whl (91.8 kB view details)

Uploaded CPython 3.10 macOS 10.13+ x86-64

diptest-0.5.0-cp39-cp39-win_amd64.whl (98.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

diptest-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

diptest-0.5.0-cp39-cp39-macosx_11_0_arm64.whl (87.5 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

diptest-0.5.0-cp39-cp39-macosx_10_13_x86_64.whl (91.9 kB view details)

Uploaded CPython 3.9 macOS 10.13+ x86-64

diptest-0.5.0-cp38-cp38-win_amd64.whl (98.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

diptest-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

diptest-0.5.0-cp38-cp38-macosx_11_0_arm64.whl (87.4 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

diptest-0.5.0-cp38-cp38-macosx_10_13_x86_64.whl (91.8 kB view details)

Uploaded CPython 3.8 macOS 10.13+ x86-64

diptest-0.5.0-cp37-cp37m-win_amd64.whl (99.2 kB view details)

Uploaded CPython 3.7m Windows x86-64

diptest-0.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (119.2 kB view details)

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

diptest-0.5.0-cp37-cp37m-macosx_10_13_x86_64.whl (91.4 kB view details)

Uploaded CPython 3.7m macOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: diptest-0.5.0.tar.gz
  • Upload date:
  • Size: 99.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for diptest-0.5.0.tar.gz
Algorithm Hash digest
SHA256 29ed636d1425879e4aa32b07bf527b49b305093e1f94b98682890bd2b501d932
MD5 e9232596cd19b4c55a496f4cabba9226
BLAKE2b-256 750285947e9e70a35b9edcd9fd745dbbcafc03cd1b5159151b80431c3b5af8aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 98.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for diptest-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b3d23b5f8bf41af1a74aac99555d2c919acb51cf461a91e55fba847ba889f8ea
MD5 3a140f6f742d091599fe8d3e08fce210
BLAKE2b-256 36f1b65f2f4e4d1fe8a625dc83ca14ca1fca823b4d6e19acd8796da053ea5a73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9544681648f681f52e1f2921a103beecebe5c5e409718f3c64891ed63be688a
MD5 b2068f5431349c1b926d3c12080768f9
BLAKE2b-256 6e331b319c9a6e9cf74a20df3e46b211428fc11d2e074d277da19c59ab0bca39

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d639a34f9557d1a9986183e5ad082533bd17bc0975759b2c538cc798d35e9cd5
MD5 f51f146f6d8d70f3a4135cbbc3531aeb
BLAKE2b-256 3b5af445b5459634d3c533a335a6b72d70b7408946a12b7ce7b8090a1e7af221

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp310-cp310-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 3f31e9eaa1be654cd16223edf6329a11945baa32be50a155e73553bdccdf6d3a
MD5 406297136814a6ed65920b9839a4b08d
BLAKE2b-256 9dd502b6781a7e26a25759e913b3c702841ddc9f55d15d0b8976555455a1daac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 98.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for diptest-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1197cbf8f3b533e68c60d9ae24d7bb31224d1c43a1882bef8a9bd0f914e6a8e1
MD5 e31be3dfe7f6a82da5bbdf3dec86cdf7
BLAKE2b-256 c68ffb558e8c4abe0d53e8c644904dfeb2575b799cc7974bacf2275ff9ffd910

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1cd44e236d5f72a91ada597d5c82aae523436cf09001e8328c8e03bca8c55243
MD5 3bc5402bd0e4b0a23533b6fae4f96889
BLAKE2b-256 22e1d29cd64e679b3f564b70a32de1e4825c3e1413cc07db6ea8a5b22a5c7521

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f094efaf48364509019d3cf64b1124652e444c6f418447210e30894cc20fef6
MD5 a1eedad70c2af08a44eb9ec8dc8be3d4
BLAKE2b-256 245dfd7faaed5c9a5d1d8a4dbb3f54557c5b66df3d52f78ab8f587cd9f15ab30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp39-cp39-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9f96c11f5336a9cec87acdf0ae29bd22d929f7572d3a225dfab7f31034375e52
MD5 1ad1724fefc20f09fdcc5f77680a6514
BLAKE2b-256 134f753a0103c2e86ffbe29047d203e7d45a1869d20048815fa98827b43389f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 98.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for diptest-0.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 91a97aa2f81c62ec8f9a785f041e0159b3679d30c5346e15ade821b8f248cdc6
MD5 d72895bc949049372c1e5d08f15c35e9
BLAKE2b-256 c2cce1ada63d30725218126c9916d5d04c22e7471d96353f4d81329ec2b81ae8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2231d5801059d5539050947f0b5eafde6ad7cf55cf1efd3a5d08c5b77a4f596a
MD5 01285ad7e0659944d0972a0607147c45
BLAKE2b-256 9383a499a04e803354f62c55eb8262b548646e47519553ae6f7a21e08cea1663

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d75c7c9965890dd9d1555f5bac8d4bc89148766c1669acc1606c3ac3ebb39441
MD5 90af44e0a81ffa87469b1540e4ee693c
BLAKE2b-256 0487f9af4a5ad67e50cb73bcb06f26c1f14809ba12d863c1af45c00d415a9f75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 c9f41b2108427c8282b5a3da09e5251d322190763ea66159dd4c99b163e775b4
MD5 5445f3dd101b23c30f3bffc4b9fb738c
BLAKE2b-256 4a118832c1e98fa59ab48ffe76691be382b0185f990240b86c98b5592445b9d4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for diptest-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ce0ad9cc0b0830d28727bf5f022736428dc2c4ef64564e66d5582086ca0d9f83
MD5 df04c6cf89e54fa327e0888e5c22e0dc
BLAKE2b-256 5da7c9f7d8e6fa7db459384657c19f99cda15c18e4c478a4ba8175ac3c5bb6de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d9c55c7ca08e6811c9b470069d257f864245bf7457ddd6a0e3b1639c33bc6319
MD5 4098b6cfeccea8f80d72a446909a00ad
BLAKE2b-256 4c50a3f88cfab38f76a41c1ee051c0bece9aad6e08ad0f9c6f39b217473ad6aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.5.0-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4bd1f5477f0ed5e0ef41b78a4ab5913f40d2ef816f58045cbc98497a96e05c64
MD5 effdb37fb05f3801e1aa4f3f76c526ad
BLAKE2b-256 e78d5be4bb8bf3b0894f8fd8f1056cac6024d62f183f397fa9a8d6f8047f1902

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