Skip to main content

Exact confidence intervals for multinomial distributions via Neyman construction

Project description

grecov

PyPI Tests Build License: MIT

Efficient Neyman construction for multinomial distributions with the Greedy Coverage algorithm.

Installation

For the IPOPT optimizer (recommended for best results):

pip install grecov[ipopt]

Development

Install in editable mode with test dependencies:

pip install -e ".[test]"

After modifying C++ code in src/ext/, rebuild with:

pip install -e .

Install pre-commit hooks to run ruff and clang-format on every commit:

pip install pre-commit
pre-commit install

Usage

from grecov import multinomial_ci

result = multinomial_ci(
    counts=[10, 10, 20, 60],
    values=[1, 2, 3, 4],
    alpha=0.05,
)
print(f"95% CI: [{result['lower']:.4f}, {result['upper']:.4f}]")

R (via reticulate)

An R package is available in r-package/ that wraps grecov using reticulate.

Installation

# Install reticulate if needed
install.packages("reticulate")

# Install the R package from the local directory
install.packages("r-package", repos = NULL, type = "source")

# Install the grecov Python package into reticulate's Python environment
grecov::install_grecov()

Usage

library(grecov)

result <- multinomial_ci(
  counts = c(10, 10, 20, 60),
  values = c(1, 2, 3, 4),
  alpha = 0.05
)
cat(sprintf("95%% CI: [%.4f, %.4f]\n", result$lower, result$upper))

The low-level BFS function is also available:

bfs <- grecov_bfs(
  p = c(0.1, 0.1, 0.2, 0.6),
  v = c(1, 2, 3, 4),
  s_obs = 330,
  n = 100L
)
cat(sprintf("P(S <= 330) = %.6f\n", bfs$prob_left))

Options

All parameters from the Python API are available:

result <- multinomial_ci(
  counts = c(10, 10, 20, 60),
  values = c(1, 2, 3, 4),
  alpha = 0.10,
  method = "greedy",
  verbose = 1L
)

Pyodide (browser / WebAssembly)

grecov compiles to WebAssembly and runs in the browser via Pyodide. The C++ BFS extension compiles unchanged; cyipopt is not included (the scipy trust-constr fallback is used automatically).

Using in a webpage

The pyodide wheel is attached to each GitHub Release. The following snippet automatically fetches the latest one:

<script src="https://cdn.jsdelivr.net/pyodide/v0.27.7/full/pyodide.js"></script>
<script type="module">
const pyodide = await loadPyodide();
await pyodide.loadPackage(["micropip", "numpy", "scipy"]);

// Find and install the latest pyodide wheel from GitHub Releases
const res = await fetch("https://api.github.com/repos/louisabraham/grecov/releases/latest");
const release = await res.json();
const wheel = release.assets.find(a => a.name.includes("pyodide"));
await pyodide.runPythonAsync(`
    import micropip
    await micropip.install("${wheel.browser_download_url}")
`);

pyodide.runPython(`
from grecov import multinomial_ci
result = multinomial_ci(
    counts=[10, 10, 20, 60],
    values=[1, 2, 3, 4],
    alpha=0.05,
)
print(f"95% CI: [{result['lower']:.4f}, {result['upper']:.4f}]")
`);
</script>

Building the Pyodide wheel locally

pip install pyodide-build
pyodide xbuildenv install
pyodide build

This requires the matching Emscripten version (pyodide config get emscripten_version). Install it via emsdk and source emsdk_env.sh before running pyodide build. The wheel is written to dist/.

Performance

Pyodide/wasm performance is on par with native CPython (~1.0x). Run the comparison benchmark with:

python profiling/bench_pyodide.py

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

grecov-0.2.2.tar.gz (37.7 kB view details)

Uploaded Source

Built Distributions

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

grecov-0.2.2-cp313-cp313-win_amd64.whl (66.6 kB view details)

Uploaded CPython 3.13Windows x86-64

grecov-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (84.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

grecov-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (80.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

grecov-0.2.2-cp313-cp313-macosx_11_0_arm64.whl (67.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

grecov-0.2.2-cp313-cp313-macosx_10_13_x86_64.whl (75.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

grecov-0.2.2-cp312-cp312-win_amd64.whl (66.6 kB view details)

Uploaded CPython 3.12Windows x86-64

grecov-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (84.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

grecov-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (80.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

grecov-0.2.2-cp312-cp312-macosx_11_0_arm64.whl (67.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

grecov-0.2.2-cp312-cp312-macosx_10_13_x86_64.whl (75.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

File details

Details for the file grecov-0.2.2.tar.gz.

File metadata

  • Download URL: grecov-0.2.2.tar.gz
  • Upload date:
  • Size: 37.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grecov-0.2.2.tar.gz
Algorithm Hash digest
SHA256 288f20118a66a71151f5000ba19b83d6f8db4325b18dd33a265adf7d6edea058
MD5 cb5ff89b685f768cba68687011d9b039
BLAKE2b-256 fc499b2179d8e5b53d98c95aba4583608cee4681fcc51fcc37f4acd34aab3359

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2.tar.gz:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: grecov-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 66.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grecov-0.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9645df073ef7357acdced82f97c61159ec6db10a229f66e72e333788ada9bdb0
MD5 e8cf13abcd3d14a10fec18693eadee07
BLAKE2b-256 700de4692a8dfe7574746ce38fada55428e3ab4dad91c99fb06c60f2e35a0347

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp313-cp313-win_amd64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9bc49f2445e0e61634c56daf43bd6775f759ad1494b3f4e3ddb06f78368b1c1a
MD5 ac4c9a2daedc323a0abc21512bd5ce7a
BLAKE2b-256 d7aac28fe6dae40ffa8423d73a5a7c3e556a2690ad16c58dc89482c9c902b20e

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 403b5437fc5253807c1d0cbd9a5e01b7d1e5bf63e9823015b2508c446ebb6349
MD5 e17ba693021dffe5d1213c8375bc2787
BLAKE2b-256 8e930a22a8cf11e46a5baaba7c87836ad4eac27ef566fa63101547c250a2ad76

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c2b52199ed928c7631411d70c71a0c964f5ed96a5dcd0a8e8334fea143d9432
MD5 7d22d366eda62ef026e72d36ea668273
BLAKE2b-256 e3e63d9d3a211bdf3abaee2727b4d37d7dddbb70e380585245f47f9223a7477c

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4ee3659349eb37a6232fa78493fb2d3e95fc0d37d36fdfc177c82d0d3de3ec0d
MD5 cbf4858d30e9a9e7c52f2b31c03ad321
BLAKE2b-256 3a31470ed3833ea4376ee0ff1e65a1ebf5953ca4cf2dda85b7b3e86d6170c977

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp313-cp313-macosx_10_13_x86_64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: grecov-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 66.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for grecov-0.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 17be5f88bc1bdb978fd8a557f302ab2ea2ea765057a4a3f0a6d783069c62f06f
MD5 2d0a958132691effc72cb2ddffa5179b
BLAKE2b-256 85c17e5e1b4c5f8d3d42328bdd063a4839a8db857fe4940a2dadfeb242f7b414

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp312-cp312-win_amd64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b81f8f6cd6de703ea3c057ba743562865a88aff16f3fb4ebd16659704d615c4
MD5 8948ac601a5167d2fc49b8cbc9fd30ab
BLAKE2b-256 ae570fb94bbe80c94b748257de81ffbefd54af7606413d3a192dcc9c8c26089e

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dcb837c7c9a5787fd07e1e41205d2dd7c797bf4cb29e1fefbe5e626ff567f7e0
MD5 b62841afd8e8752bcdb015a0de9a5548
BLAKE2b-256 1ae0b54f4f86593b54c40c57d67b2becc4d72e89d77090bb528b2dad0cd15317

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 392e7692fafd6d12bf486da7d0d2ac60fbf72fccbb92a3ba54e9a079b330db25
MD5 9f4d5124c0e242460c57aaf86157b97c
BLAKE2b-256 1c03cadc536ab87071c5bfaef1a8e355ae93ec5fe606293af571cfc398f5c5ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build.yml on louisabraham/grecov

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

File details

Details for the file grecov-0.2.2-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for grecov-0.2.2-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 5f738619b134d262c1dc456385b6e52766fc37704ebba578daff3c1fbcd28187
MD5 6ad8044e4a490e653c367d113fb37228
BLAKE2b-256 e3a86b5f906c67e2fa89eae64f49dd728619f3400525031a64afcad13abc2ced

See more details on using hashes here.

Provenance

The following attestation bundles were made for grecov-0.2.2-cp312-cp312-macosx_10_13_x86_64.whl:

Publisher: build.yml on louisabraham/grecov

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