Optimal confidence intervals for the hypergeometric distribution success parameter using the Alpha-Max-Optimal (AMO) method.
Project description
hyperMCI
A Python package for calculating optimal confidence intervals for the hypergeometric distribution success parameter.
Description
hyperMCI implements the Alpha-Max-Optimal (AMO) confidence interval method described by Bartroff et al. (2022) in "Optimal and fast confidence intervals for hypergeometric successes". It provides efficient algorithms for computing confidence intervals with guaranteed coverage probability for the hypergeometric distribution — useful in audit sampling, clinical trials, quality control, and survey statistics.
Installation
pip install hyperMCI
Or, if you use Poetry:
poetry add hyperMCI
Quick Start
from hyperMCI import get_success_confidence_interval
# 95% CI for M given x=3 successes in a sample of n=10 from N=100
lower, upper = get_success_confidence_interval(x=3, n=10, N=100, alpha=0.05)
print(f"95% Confidence interval for M: [{lower}, {upper}]")
Usage
Single observation
from hyperMCI import get_success_confidence_interval
lower, upper = get_success_confidence_interval(x=5, n=20, N=200, alpha=0.05)
print(f"95% CI: [{lower}, {upper}]")
Multiple observations at once
import numpy as np
from hyperMCI import get_success_confidence_interval
observations = [2, 5, 8, 10]
lowers, uppers = get_success_confidence_interval(x=observations, n=20, N=200, alpha=0.05)
for x, lo, hi in zip(observations, lowers, uppers):
print(f"x={x}: CI=[{lo}, {hi}]")
Access the acceptance intervals directly
from hyperMCI import get_enhanced_acceptance_intervals
# a_star[M] and b_star[M] give the acceptance interval bounds for each M
a_star, b_star = get_enhanced_acceptance_intervals(n=20, N=200, alpha=0.05)
Features
- Optimal CIs: Implements the AMO method for shortest possible confidence intervals while maintaining the desired coverage probability.
- Scalar and batch support:
get_success_confidence_intervalaccepts a single integer or any array-like input. - Minimal dependencies: Only requires NumPy.
- Fully typed: Ships with a
py.typedmarker for PEP 561 compliance.
Mathematical Background
The hypergeometric distribution models sampling without replacement from a finite population. Given a population of size N containing M successes, the probability of observing x successes in a sample of size n follows:
P(X = x | M, n, N) = C(M, x) * C(N-M, n-x) / C(N, n)
This package implements the Alpha-Max-Optimal (AMO) confidence intervals described by Bartroff et al. (2022), which provide shorter intervals while maintaining the desired coverage probability compared to classical methods (e.g., Clopper-Pearson adapted to the hypergeometric setting).
Citation
If you use this package in your research, please cite:
@article{bartroff2022optimal,
title = {Optimal and fast confidence intervals for hypergeometric successes},
author = {Bartroff, Jay and others},
year = {2022}
}
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hypermci-0.1.0.tar.gz.
File metadata
- Download URL: hypermci-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f46c5a0d9a8513df1962ad64ec072289fb6f87fee3e351d151b94ad27febcb78
|
|
| MD5 |
20b8e75590a7503047e18a776a2e8fd6
|
|
| BLAKE2b-256 |
9528c21ceda8e914eb23b445e6762c889207aa4ec8d42aad50c97ef7287de2a4
|
Provenance
The following attestation bundles were made for hypermci-0.1.0.tar.gz:
Publisher:
publish.yml on oresthes/hyperMCI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypermci-0.1.0.tar.gz -
Subject digest:
f46c5a0d9a8513df1962ad64ec072289fb6f87fee3e351d151b94ad27febcb78 - Sigstore transparency entry: 2119169685
- Sigstore integration time:
-
Permalink:
oresthes/hyperMCI@da2c799b229c0518da4b174fc7eaecaf540f1254 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/oresthes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da2c799b229c0518da4b174fc7eaecaf540f1254 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hypermci-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hypermci-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bcf7d62898cdae7e4e98f48554b1e5580f928e6bdf0520fff4fbfb60606a82e
|
|
| MD5 |
c455e807f2ad2052780ef3062c559bd8
|
|
| BLAKE2b-256 |
fe13e6cdc66675d3fa11622b0ee30b8beba8a936834b2ad07ab7363d94066cda
|
Provenance
The following attestation bundles were made for hypermci-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on oresthes/hyperMCI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypermci-0.1.0-py3-none-any.whl -
Subject digest:
9bcf7d62898cdae7e4e98f48554b1e5580f928e6bdf0520fff4fbfb60606a82e - Sigstore transparency entry: 2119169739
- Sigstore integration time:
-
Permalink:
oresthes/hyperMCI@da2c799b229c0518da4b174fc7eaecaf540f1254 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/oresthes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@da2c799b229c0518da4b174fc7eaecaf540f1254 -
Trigger Event:
release
-
Statement type: