Skip to main content

Accurate and efficient binomial, Hardy-Weinberg equilibrium, and Fisher's exact tests.

Project description

exact_tests

This package implements the binomial, Hardy-Weinberg equilibrium, and Fisher's exact tests (2x2 and 2x3 so far), along with corresponding discrete distributions (binomial, hypergeometric). scipy- and R-style interfaces are provided.

As of this writing, these functions are more accurate, and often simultaneously more efficient, than their scipy counterparts: see the MPFR-comparison and benchmark scripts under utils/ . E.g.

$ utils/pbinom_accuracy.py
n in [2^5, 2^6): RMS=0.0  approxRMS=7.306071560616266e-17  scipyRMS=0.0
n in [2^20, 2^21): RMS=0.0  approxRMS=1.2526064965951066e-15  scipyRMS=2.1803173153679657e-15
n in [2^35, 2^36): RMS=0.0  approxRMS=6.765221412952766e-15  scipyRMS=1.151310810012349e-14
$ utils/pbinom_accuracy.py --z-score -2
n in [2^5, 2^6): RMS=6.50688277690206e-17  approxRMS=2.4782896885670045e-16  scipyRMS=1.961761908748987e-16
n in [2^20, 2^21): RMS=0.0  approxRMS=5.081502940565382e-16  scipyRMS=1.0124311233166742e-13
n in [2^35, 2^36): RMS=0.0  approxRMS=6.870911531925403e-16  scipyRMS=1.6632421178076063e-11
$ utils/pbinom_accuracy.py -p 0.1
n in [2^5, 2^6): RMS=0.0  approxRMS=1.0628000483584193e-16  scipyRMS=4.2242773368500245e-16
n in [2^20, 2^21): RMS=0.0  approxRMS=1.6240941533512943e-15  scipyRMS=1.2335258925049512e-11
n in [2^35, 2^36): RMS=0.0  approxRMS=5.482663890316387e-15  scipyRMS=3.466853038093633e-07
$ utils/pbinom_benchmark.py
n=(2^5)-1: base=9.99998883344233e-07  approx=2.582994056865573e-07  scipy=3.0166699434630573e-05 sec/iter
n=(2^20)-1: base=4.6941702021285894e-05  approx=3.274998744018376e-06  scipy=2.860420208889991e-05 sec/iter
n=(2^35)-1: base=0.0011365917016519234  approx=7.932920125313103e-05  scipy=9.544169879518449e-05 sec/iter
$ utils/phyper_accuracy.py
n in [2^5, 2^6): RMS=0.0  approxRMS=1.2783240627107975e-16  scipyRMS=3.2668147214494056e-16
n in [2^20, 2^21): RMS=0.0  approxRMS=7.594696303752788e-16  scipyRMS=2.7605400523075697e-10
n in [2^35, 2^36): RMS=0.0  approxRMS=1.639999166953556e-14  scipyRMS=1.2741882006508117e-05
$ utils/phyper_benchmark.py
n=(2^5)-1: base=2.847324746350447e-06  approx=4.306687818219264e-07  scipy=4.3361001492788397e-05 sec/iter
n=(2^20)-1: base=7.218066214894255e-05  approx=5.430668049181501e-06  scipy=0.0004969029978383332 sec/iter
n=(2^35)-1: base=0.014636972337029874  approx=0.0008547363298324248  scipy=14.766715555665238 sec/iter

The primary building block is a high-precision log-factorial function utilizing the QD library (https://github.com/BL-highprecision/QD ).

Build instructions

PyPI:

python -m pip install 'pip>=20.3'
python -m pip install exact_tests

GitHub:

python -m pip install 'pip>=20.3'
python -m pip install -e 'git+https://github.com/chrchang/stats.git#egg=exact_tests&subdirectory=Python'

Or install from a cloned copy:

# clone repo
git clone https://github.com/chrchang/stats
# go to python folder
cd stats/Python
# install the package
python -m pip install -e .

You can test the package with pytest.

Example usage:
import exact_tests

exact_tests.binomtest(3, n=15, p=0.1, alternative="greater")
exact_tests.binomtest(2, 29, 0.1)
exact_tests.binomtest(2, 29, "0.1")
exact_tests.binomtest(2, 29, "0.1", midp=True)
exact_tests.binomtest(100, 10000, "0.000001", logp=True)
exact_tests.fisher_exact([[4, 0], [0, 4]], alternative="greater", midp=True)
exact_tests.fisher_exact([[10000, 20000], [30000, 40000], [50000, 60000]], logp=True)

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

exact_tests-0.6.1.tar.gz (238.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

exact_tests-0.6.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

exact_tests-0.6.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

exact_tests-0.6.1-cp314-cp314-macosx_10_15_universal2.whl (506.3 kB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

exact_tests-0.6.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

exact_tests-0.6.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

exact_tests-0.6.1-cp313-cp313-macosx_10_13_universal2.whl (502.3 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

exact_tests-0.6.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

exact_tests-0.6.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

exact_tests-0.6.1-cp312-cp312-macosx_10_13_universal2.whl (504.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

exact_tests-0.6.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

exact_tests-0.6.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

exact_tests-0.6.1-cp311-cp311-macosx_10_9_universal2.whl (501.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

exact_tests-0.6.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

exact_tests-0.6.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

exact_tests-0.6.1-cp310-cp310-macosx_10_9_universal2.whl (501.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file exact_tests-0.6.1.tar.gz.

File metadata

  • Download URL: exact_tests-0.6.1.tar.gz
  • Upload date:
  • Size: 238.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for exact_tests-0.6.1.tar.gz
Algorithm Hash digest
SHA256 9528b60d1b13212f6bcb7d56bc4b0abdd354f07d1a53c5dc6f4d87d86d38d0eb
MD5 1ba99890b43310997fde1e865f80858a
BLAKE2b-256 d8c7b2f04a4cfdf28205e4eba6703091bdc0b4e2aa24540b0fe7b991bebc579c

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1.tar.gz:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 950d8f6a3327aa9ac248e539e7df786419ce3575a7bcc5d22ddd06a197223eda
MD5 cf268d9bc9526abe77157f683d731f99
BLAKE2b-256 6c100e5ffcd5db677ece560f403a5347521963118bd9c7298163562552f9e7a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 6f2df67169605cd1a8b94cc3b8d5c13807b89ffb34d467fcd7f12e4fbc98f5a9
MD5 46fc8ab651674c63fccd16424b1d20d9
BLAKE2b-256 dba32c80735850732b74cd69502f378a147a057e61f7b81eae3f7dc24d685dc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 df2110ad0a8c559d588483e00ee97cc6d60857dc656d278225529e71a317a77b
MD5 4eab0641bc91fb6eaa81235cc5594788
BLAKE2b-256 202c6df6c760f35a61576c68ef2551a8f658642390ea1bad8d8459af71a17fff

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp314-cp314-macosx_10_15_universal2.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 24b126ad6d5f3229160801ac72b65a00abfd94ace4284162db0c50a58f3938b9
MD5 2fc0ad43802c1ccc4b0939739a44d795
BLAKE2b-256 4e8c1aa2d4973a2b0e9318e15c7e5abd77dabfbebc61e8255ca2fd95fa467390

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 214f9406020a6f8352be10fadbdfde6c76522bc9f5e18357b823d73aacc54182
MD5 c4f5f10df8014093072e569352f525ea
BLAKE2b-256 cfb64d44eafa4f52f1312f5ddfcc91d9933da4050db50b9367c25cc6fa313834

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 34320b6cd04aa92fbc140ad5091ccee1b4f0580480ae0f9f21510bd65f3b05c9
MD5 dab0ccf763a4705deff70826c5f4fb3a
BLAKE2b-256 513423099e7689221406331705e715b824ff81bf00c1227f75720307dc13f73e

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fb0c5e2ebe8b7dc64e2c87ee03b5298681e5f6168f86a0a33a4f5726b8614f5a
MD5 305f5d4c8ce162686eeb837a885c5229
BLAKE2b-256 7b0af9356728d7f9c637274a6537ceea953108d06c2f7b06935de46308ae1d3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 20cc17b6d07ab5297f87ad05b9299dd649cf777d302d98b255946313bdad2a44
MD5 3686421e5bc578927af5f307200f1179
BLAKE2b-256 cab34241018382ff1bac0bf2ce87a820c259e3824abc2125abbac879fcc8965f

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 1e28343d512e457b6c3dcdac634111ebbaf4bb7c1d7ae26ec5999d9395b6095f
MD5 5998860a3ba1abfaab6fdcf8c3c559bc
BLAKE2b-256 a30ffc752570eda3b34009a90c5906afa6e4da78ce618398723db464f813d89a

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 edd91c0a7f090e3eeea1b4d3f7cc7b1b0026be165648ab9d4aca1b8ddac32092
MD5 afa4140136ce92cfd3fbd4208defa9e2
BLAKE2b-256 35362494d629e3388f806d516bb48d2f76552bdf1c79e678f803e148801e0d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0005741ca491bd228bcc248f7ab31b03c2f4cdebc2a1269f66b43cdcc9a21df4
MD5 3d4eef0a426b792bf8888e19fa97cf85
BLAKE2b-256 8100d50f304bb59a479c72b643bebfdbd5523d5f22a0da733c59ba9bec9924d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b692e4a33157c5317908d90ed794301ece92bc2190263e6530310b868404877b
MD5 db6acdadfbc5bfd2a59b3c4c23b5d661
BLAKE2b-256 65c000da90656d88dc5b11e5a6f1462036ecdff8a35bd2489bdf48c5faeeb682

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 77d3660145d7296ddbe4be8f670a58ef0bc51135b41b0f86cfb2147b0568cba9
MD5 c8c90e4958f275077938251c864eb798
BLAKE2b-256 bfdd85ef2bd69e752622324f6b9b99deca76981e220108da33a673fcee977063

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 247955e6c1ab7fdbd360c0dc166307d8d254e971cea45b01a7abde484f21b082
MD5 bdda332849e1bc80011736d38044b576
BLAKE2b-256 ce91146d79f5983fe58046dd4e2f3dfb05c3cf64461951f7efd410d4d481dd6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file exact_tests-0.6.1-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.1-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c8d45138e5d6d0553b0c04beb2dafb26ef9a4fb58647598b6dc648ebc9ff7d63
MD5 388c2d0770f7dc008866b8e8c28d9fbe
BLAKE2b-256 be32a4d106f57e525da130b8841668036f7901e5480475b351f4c2dcd876e6d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.1-cp310-cp310-macosx_10_9_universal2.whl:

Publisher: release.yaml on chrchang/stats

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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