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.0.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.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: confinterval-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 6a7c943b6c0796bfcc6a560bf36aed5a17bfdfa4b811e27e82ce72ccc59e6b81
MD5 85b6ce6743b86df33581690f69cc5a39
BLAKE2b-256 41c488f6b96564f6d04697b23c13868fe0df349b2a70a27b0402940c4232b3ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for confinterval-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: confinterval-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f403ea7a44a63df1c73c7daa1f7ef5331e7e4c40d133ee1ce3b118bf5fd022a
MD5 8baf0f04f06713fdf142eb4952d979c5
BLAKE2b-256 69ab8da15b8cc5092159eed6f205de336a6a59169f219404aae716b2d0b53b1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for confinterval-0.1.0-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