Skip to main content

Simple confidence intervals for Python.

Project description

confinterval

PyPI version   Python versions   License: MIT   Downloads

A lightweight Python toolkit for computing confidence intervals for means, medians, percentiles, and proportions.

It supports:

  • t confidence intervals for the mean
  • normal approximation confidence intervals for the mean
  • bootstrap confidence intervals for mean, median, standard deviation, IQR, and percentiles
  • Wilson confidence intervals for proportions

Installation

Intsall confinterval from PyPI

pip install confinterval

Quick Start

from confinterval import ci

data = [18, 19, 20, 21, 22, 20, 19, 21, 20, 22]

result = ci(data, confidence=0.95).t()

print(result)

Output:

mean: 20.2
95% t confidence interval: [19.384, 21.016]

You can also access the values directly:

result.estimate
result.lower
result.upper
result.confidence
result.method
result.statistic

Bootstrap intervals

Bootstrap intervals are useful for statistics like the median or percentiles.

from confinterval import ci

data = [18, 19, 20, 21, 22, 20, 19, 21, 20, 22]

result = ci(data, confidence=0.95, random_state=42).bootstrap("median")

print(result)

Output:

median: 20
95% bootstrap confidence interval: [19, 21]

You can use:

ci(data).bootstrap("mean")
ci(data).bootstrap("median")
ci(data).bootstrap("std")
ci(data).bootstrap("iqr")
ci(data).bootstrap("p90")
ci(data).bootstrap("p95")

Proportion intervals

Use Wilson intervals for proportions, rates, or percentages.

from confinterval import ci

result = ci.proportion(87, 100, confidence=0.95).wilson()

print(result)

This means 87 successes out of 100 total trials.

Output:

proportion: 0.87
95% wilson confidence interval: [0.790196, 0.922428]

Confidence level

The default confidence level is 95%. You can change it:

ci(data, confidence=0.90).t()
ci(data, confidence=0.99).bootstrap("median")
ci.proportion(87, 100, confidence=0.95).wilson()

Higher confidence gives a wider interval.

Convert result to dictionary

data = [18, 19, 20, 21, 22, 20, 19, 21, 20, 22]

result = ci(data).t()

result.to_dict()

Output:

{'estimate': 20.2,
 'lower': 19.25818886972757,
 'upper': 21.14181113027243,
 'confidence': 0.95,
 'method': 't',
 'statistic': 'mean'}

License

This project is under the MIT License.

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

confinterval-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

confinterval-0.1.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file confinterval-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for confinterval-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dc7f50a498f7d161f62b355ff03cfec7fc3a40d6f2719c4b7b37faec5f2a8da5
MD5 bbb5fa63a90d74f3e51ce596e37e3873
BLAKE2b-256 be1ffbc656d3bcc9ba94f645f0ae86e022c288aa05951bcf96ee1e9c2c69df39

See more details on using hashes here.

Provenance

The following attestation bundles were made for confinterval-0.1.1.tar.gz:

Publisher: python-publish.yml on semoglou/confinterval

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

File details

Details for the file confinterval-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: confinterval-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for confinterval-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5ddfee864b2491c541f5cd97330e615c6bbca61e14d8aa24e209a3d0a28636db
MD5 23cd703aee8ece8d405b3c02f315b6d6
BLAKE2b-256 e16695128cbd76608fbce6d41854cfd8283f9c2fdc6e6f7e71c2c70b75d44365

See more details on using hashes here.

Provenance

The following attestation bundles were made for confinterval-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on semoglou/confinterval

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