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.0.tar.gz (238.3 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.0-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.0-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.0-cp314-cp314-macosx_10_15_universal2.whl (505.2 kB view details)

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

exact_tests-0.6.0-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.0-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.0-cp313-cp313-macosx_10_13_universal2.whl (501.3 kB view details)

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

exact_tests-0.6.0-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.0-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.0-cp312-cp312-macosx_10_13_universal2.whl (503.1 kB view details)

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

exact_tests-0.6.0-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.0-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.0-cp311-cp311-macosx_10_9_universal2.whl (500.1 kB view details)

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

exact_tests-0.6.0-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.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.5 MB view details)

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

exact_tests-0.6.0-cp310-cp310-macosx_10_9_universal2.whl (500.7 kB view details)

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

File details

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

File metadata

  • Download URL: exact_tests-0.6.0.tar.gz
  • Upload date:
  • Size: 238.3 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.0.tar.gz
Algorithm Hash digest
SHA256 7393198539ce7ff15dff4bed4ed1524482582524c722c4e838a7be495e92b5fd
MD5 7a8ac08edb6cdd57cbd9615fe5e1329a
BLAKE2b-256 c2984c278c92b6c9fda9b33cb7b725d00b393c9dacd8a2bf641321e5e5f4a0e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0.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.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1623ecaafd3e17d5c6bca885b867b2894e2b16fcf98529bfbb252be666458d96
MD5 ab5aebe634c4a319fa7a701429b48954
BLAKE2b-256 d7f95935cec9de3f2097ee1ba3c5bbc03931771b7fa79e54993db038f6817578

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-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.0-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 63f46b1e80c614cedee293633e89997dac9122a9e37925c26641a393b55f3e7d
MD5 f947b4c2936084a30eb31f050240f4ae
BLAKE2b-256 777ccc7a4248ca999d40a19ac31768c08342678471b52efe92a297fd8aa0c59b

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 6f73fbcf1d2d3d02e36599c47330e98ef6b55633addf3387b671d7c0cf420d6e
MD5 8e5f8c073ee1feae14ac41864afd7e1d
BLAKE2b-256 4e695902e8830d866712dc582d1e634245240e704fef7afa2eee90f1026f8258

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e2cf9cab91160f0235d08d0d44c5d70e140f189b1b129403ad1f4dd83e94bc57
MD5 ec735702ae7bd441a95c4ce4f8dca222
BLAKE2b-256 58b65cfc828159f59945e18ce3044e4fa4fe4153de8bb2ae9242bdee742fb44b

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-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.0-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 e95ab00665c3c9024f92846c02b0de633be5f7d9d0de833fd025dff775dbec0c
MD5 ebc859e9696ab7ea4eb9bdd0845ee0c5
BLAKE2b-256 6a76efdcfd839ae3dfa6bd881ffac4cb79155b8095bdb75262035168af5bd912

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a3508dcbe24a435ebb0b8c496d1907ea51e601051f79ea17d63c2b83ef3d9dee
MD5 504e75d4ecd73860c9a847ac00c51344
BLAKE2b-256 c92fd63bf53c6cb0f1285fdabbef78da4c6b728ca0e8e45efc71af6fdc7ba6e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 64a18b163f25ce5c5ccd6240f2dfcc4a1248f75afedf9d90afbf3508bf3f1150
MD5 afb0e8be3083d4c69c16ecdd771034c0
BLAKE2b-256 d04552f231bf99ada9d1c565196ba6ed1698855d54831850fe7682148f924300

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-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.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 69d14a768ecf34a803c5e9ff7c8f4a802138657284a956d7b5ca6825e5f714e3
MD5 fc49998b61593e66aec2ebd5958c9c18
BLAKE2b-256 caa4c05344dd1896b8883f0bf6df6e2de05b642a559e2638cee579935f854a0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 9a8779c2f8ea8d5912538e0345ae66d391d7564cb34d1a0f3f0e1874edd3abdc
MD5 b927a94f15aca18d4ff031567749562b
BLAKE2b-256 516f00d82b7772d14713740cf8d11475548a9efa4a25f14fe21bea0a77e29d3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 50600cd0e96792541a59bdef5bcd038108d7df8de3d498b55533d052c4e2e48a
MD5 8c11be77fec81f9e4bb2259d3275c294
BLAKE2b-256 02891f3a4b89e8e970ba60d33c0a546a98d6fe6553619b4ec4e5a213b8e573ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-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.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c64ac17532035791d2af0a958e17de2ee135d35710d2d1c231c20ed49f716cc1
MD5 c0de3683318242ac0a089cbbc865a1fb
BLAKE2b-256 1858a3b2e908952fe11a93dd93fcbf04e1e112ee8ac9ed3ee931a43e337f43b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 134a6d89979866bd08773afee4ce2ae1e54366e7e0546c16ed61842f8b4e8592
MD5 80c35fe08e0d52add24f2d698db95d93
BLAKE2b-256 d6688a3b17b72f571f33ac348cba3d74fccd38f95bc88dca936d41673e87cd45

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 570d28ceda5c17ad9372cd995a3d5ea651c4802c700a7472f65ef9e55d68e834
MD5 8b679b841876d64a91823210018b7c19
BLAKE2b-256 b02275fba0505e9d53de2777f9d519c1b031dc1c5115226721908de78e81342a

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-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.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f6838c5666be2481b3a17c5176b273a47d2262fd257b4e520018f9790a2ca056
MD5 4aae891d4a62e765a93c5719985e9e34
BLAKE2b-256 756401bdb83c912ccedf9588bff0a0ce5a22c50d2e93bb90ca4681c40ec308f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for exact_tests-0.6.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 a8b9c3b22f25fe2d8c41133980daeee995c23cb3ebdbca806273439420d7c8fc
MD5 8bfd1b97fb33577a1e3a988aa388ba24
BLAKE2b-256 9efba47185642204d3fe890c09fd3f1a67be76c96b471bf0cbebcb3bbeae8834

See more details on using hashes here.

Provenance

The following attestation bundles were made for exact_tests-0.6.0-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