Skip to main content

Hartigan's diptest.

Project description

diptest

Linux Build Windows Build MacOS build PyPi

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.

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)

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.8 - 3.12
  • Linux x84-64 - CPython 3.8 - 3.12
  • MacOS x84-64 - CPython 3.8 - 3.12
  • MacOS ARM-64 - CPython 3.8 - 3.12

Note that the wheels vendor/ships OpenMP with the extension to provide parallelisation out-of-the-box. If you run into issue with multiple versions of OpenMP being loaded you have two options: build from source or install a non-bundled wheel.

Non-bundled wheels

We provide the same wheels without OpenMP bundled here: https://github.com/RUrlus/diptest/releases You than install the wheel that corresponds to your Python and OS. For example, for CPython 3.11 and MacOS ARM:

pip install diptest-0.8.0-cp311-cp311-macosx_11_0_arm64.whl

Building from source

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)

Disable OpenMP

To disable OpenMP use:

    SKBUILD_CMAKE_ARGS="-DDIPTEST_DISABLE_OPENMP=ON" pip install diptest --no-binary diptest

Debug installation

To enable a debug build use:

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

Debug printing

To enable the debug print statements use:

    SKBUILD_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)

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

Uploaded Source

Built Distributions

diptest-0.8.1-cp312-cp312-win_amd64.whl (400.5 kB view details)

Uploaded CPython 3.12 Windows x86-64

diptest-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.8 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp312-cp312-macosx_12_0_x86_64.whl (417.7 kB view details)

Uploaded CPython 3.12 macOS 12.0+ x86-64

diptest-0.8.1-cp312-cp312-macosx_12_0_arm64.whl (368.1 kB view details)

Uploaded CPython 3.12 macOS 12.0+ ARM64

diptest-0.8.1-cp311-cp311-win_amd64.whl (400.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

diptest-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (197.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp311-cp311-macosx_12_0_x86_64.whl (418.8 kB view details)

Uploaded CPython 3.11 macOS 12.0+ x86-64

diptest-0.8.1-cp311-cp311-macosx_12_0_arm64.whl (368.8 kB view details)

Uploaded CPython 3.11 macOS 12.0+ ARM64

diptest-0.8.1-cp310-cp310-win_amd64.whl (399.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

diptest-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp310-cp310-macosx_12_0_x86_64.whl (417.3 kB view details)

Uploaded CPython 3.10 macOS 12.0+ x86-64

diptest-0.8.1-cp310-cp310-macosx_12_0_arm64.whl (367.4 kB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

diptest-0.8.1-cp39-cp39-win_amd64.whl (400.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

diptest-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp39-cp39-macosx_12_0_x86_64.whl (417.4 kB view details)

Uploaded CPython 3.9 macOS 12.0+ x86-64

diptest-0.8.1-cp39-cp39-macosx_12_0_arm64.whl (367.5 kB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

diptest-0.8.1-cp38-cp38-win_amd64.whl (420.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

diptest-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (196.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

diptest-0.8.1-cp38-cp38-macosx_12_0_x86_64.whl (417.2 kB view details)

Uploaded CPython 3.8 macOS 12.0+ x86-64

diptest-0.8.1-cp38-cp38-macosx_12_0_arm64.whl (367.3 kB view details)

Uploaded CPython 3.8 macOS 12.0+ ARM64

File details

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

File metadata

  • Download URL: diptest-0.8.1.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1.tar.gz
Algorithm Hash digest
SHA256 7f91b681e7cef0123fb237e91fbc00cb6ee23e8ef7d86628675ad2503bef0f91
MD5 b3c2b645c0fe51ce95b92ec81dfa41c2
BLAKE2b-256 8e4c619d329d439c647e0b5e8e2e63bc18678f4ff5d33bc71b78a4d7ada14f5f

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: diptest-0.8.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 400.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 73c3a486ed91b2e25a1ea63a540d14025ffc2ade9c19114f8d06c963ee16e378
MD5 97c196437c04d8dd9a24c17d781432b9
BLAKE2b-256 8b37dc16a3ed02244910f7171064e896a5af39aed72531e231ead2ba72925930

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 adf37431de96a1e79dc74f0a3922fe9efff01e3ff4491aa3aebe27a80e934f83
MD5 5e6ac613ad977b44b3d03d10ad28e330
BLAKE2b-256 d2ad5f28e41cf6130b84a325e99ad72bb351b158ae4eab804dd5d1e9289f1624

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp312-cp312-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp312-cp312-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 195024dd54deb36460499b4d4b3d6970d57b1e94229c871d90da6bbad98267b8
MD5 3be5c618f9e05b79007f2c4871882b52
BLAKE2b-256 c8e973133715f48507630bc062f3452d411e955ade12c4222a2ca3a849f5ac70

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp312-cp312-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 53b8f089f7138f39dc82226883aad5cb19fa12fbd52822f37656616a2f4b6540
MD5 a993553a72f986ada49f597eee4d1ad2
BLAKE2b-256 d575ebdf004b5d7e171f281debfd6d0eec3e0afffd6f133b3820f4d5bfe230ae

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: diptest-0.8.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 400.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 cac1821d23d46bc8be1437a81c8fbd203623d5567ee0e08efa639085e30addab
MD5 b5c838fb75d1f86a129c26aa828fef14
BLAKE2b-256 e6bbaa60f8f58c099a235f77fa8d645d85f32eadbd6b88dc33b22438d951c4a9

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6cae86c1aeecc2df4753dd816b6b9fae05b640c8e02d3ed7a038762c61281f5a
MD5 47da052494b322f55b99ffd231f64d08
BLAKE2b-256 97736fcd47ba185ac15d42f2497ff5de734d68c481883329edc568355bd73615

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp311-cp311-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp311-cp311-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 2b2da028ad6fe4c7cd91106c441d8de9ec33c0f754410db28f71cb4d45e42531
MD5 6aebb4d7eff1f3ce26991ea182902a9a
BLAKE2b-256 fbf9e9f0a8e8f4ae8cf1db2ee9cfe02ad90792b77a3c0c1f54879f975ff16683

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 aaacd5ddbeb98e5b838e2afd3fdc53eac88514fd3c2abda5956bf35dc908c108
MD5 3f21c95f9b6400395c99951589c0fdd9
BLAKE2b-256 f5c4f5e2c6e2163d8c75337424a1bf3839effad87118d16dcfda401ee5938754

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.8.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 399.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7a4f1882ae6c76193235d9e3a047effa60c4a25e9590d16c58fea74d5dda909f
MD5 a2780d8a861112cb101bfcc8db44d24a
BLAKE2b-256 d50f063deccec05ee3ee914ac7ff2a7abf9238ee1d7e6dc3b612cd66a9e0e889

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.8.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1affb916146bb93726a3c8e599f8f8acc73961057e7bb3cb15afc693b317aa7
MD5 2932859c80f25ef9b60852efe1a32e13
BLAKE2b-256 92649b90918f0e67ec06c6749d622686e05ce850233b70fd0bb188c9b37a616f

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp310-cp310-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp310-cp310-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 1abbfdade2b6755f12e1b5c44a6d0623e32c98f933a64d8dc13a1b1f8ad0dedb
MD5 a984884b7f1dc8d917ce0c95c1d81bbf
BLAKE2b-256 1ed3792f8fcfee5b287b5ead00ccd13633395c67c1ea1c3e58cc2afef94e35f8

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b9500930f2d11444ecda0617d4425add2a4d2f5b4630ec7ef449b42b32bc4ed1
MD5 40819e21979c3cbed2b9a7d86ae8a11c
BLAKE2b-256 51913a7acb8e6d79d2f9dd2262cf53bd2da237321f98c7274869cc3fd3f8f90c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.8.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 400.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ee224b2144cfd67a6681a427a11d191d9b8ef75e73cf4c02b5a71e3ff8f7cb7b
MD5 904c3ecb7329c07aeda8a5878597cff1
BLAKE2b-256 c35f01b7085841815f9c13e0cd86c2bae228b037744eb3e8554804c90952e5cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.8.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6aee15b7f46c7cb93c77ba041df39a2185bf06c620c96cfdf46ca88eb7d4a09e
MD5 91e9636ab0c97dd6f361d825310b8a0c
BLAKE2b-256 726563bc6aa61f6b41974ab260f77c3fa4ca52258b667713e69282717b34b6a9

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp39-cp39-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp39-cp39-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 f68dd4264af576bfeb0dd21e36540ce7873342689d5f72944964fc129cee2e78
MD5 a61d17af30eae9f90370d868b988da4d
BLAKE2b-256 4436b297b51951645c1dbd5f3a3d6a3a4f623749840c72f726e8fdc3316246a2

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 eae2192f78f0bf3fa80a1c06fa614340d51370366dd157733cc53360025c7def
MD5 f42dbec6a90a4b320e8346c0587850e4
BLAKE2b-256 186d9e9a2f4a48df6ad2ae1854bf75a10624297131d966cd3dfba49d6b2ae21c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: diptest-0.8.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 420.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for diptest-0.8.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9d81e444b9f28b6b826d8690b94e28c7b6d54b0fe66526df4af5df62edc42a25
MD5 22269c9247adeca8f3557568f9f95f63
BLAKE2b-256 b9cd1a2605419796d13ff4ce7e5a27d7ea90d4634f71f4f55830c0240fb1b207

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for diptest-0.8.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 40c7f129183862251cc4baaf0292a95ea0fc7393a6df125eabeef740b5ebacff
MD5 87ca336c69dc77cbf95aec9daf2557e8
BLAKE2b-256 44decbffe3278c3989670bb1eab885ca494201a93e201225e36b522323b0e428

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp38-cp38-macosx_12_0_x86_64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp38-cp38-macosx_12_0_x86_64.whl
Algorithm Hash digest
SHA256 4e392006f2b523a6cd823846b44c1bff9c22ea2eee6c77822a40e90e9b64c993
MD5 10aa4de131d31e1bc90aa26c8f680069
BLAKE2b-256 b398fcdec2b9c20f4f0e92a821eeb326bbd69afaade8192c339dead1c1bd2502

See more details on using hashes here.

File details

Details for the file diptest-0.8.1-cp38-cp38-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for diptest-0.8.1-cp38-cp38-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b11474152b09c98ce065100c402593bc80085f687a1d57addb873c6da4c2f036
MD5 077a028c3ec62900f901d16c5ba93697
BLAKE2b-256 081324cf8a01de8142b935d0df004b22c8632ca77bd602a4ee07c63efc14498c

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