Simple confidence intervals for Python.
Project description
confinterval
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a7c943b6c0796bfcc6a560bf36aed5a17bfdfa4b811e27e82ce72ccc59e6b81
|
|
| MD5 |
85b6ce6743b86df33581690f69cc5a39
|
|
| BLAKE2b-256 |
41c488f6b96564f6d04697b23c13868fe0df349b2a70a27b0402940c4232b3ea
|
Provenance
The following attestation bundles were made for confinterval-0.1.0.tar.gz:
Publisher:
python-publish.yml on semoglou/confinterval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confinterval-0.1.0.tar.gz -
Subject digest:
6a7c943b6c0796bfcc6a560bf36aed5a17bfdfa4b811e27e82ce72ccc59e6b81 - Sigstore transparency entry: 1536434419
- Sigstore integration time:
-
Permalink:
semoglou/confinterval@f382134179e121239aed1f7fa3b7d497cea7b444 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/semoglou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f382134179e121239aed1f7fa3b7d497cea7b444 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f403ea7a44a63df1c73c7daa1f7ef5331e7e4c40d133ee1ce3b118bf5fd022a
|
|
| MD5 |
8baf0f04f06713fdf142eb4952d979c5
|
|
| BLAKE2b-256 |
69ab8da15b8cc5092159eed6f205de336a6a59169f219404aae716b2d0b53b1e
|
Provenance
The following attestation bundles were made for confinterval-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on semoglou/confinterval
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
confinterval-0.1.0-py3-none-any.whl -
Subject digest:
3f403ea7a44a63df1c73c7daa1f7ef5331e7e4c40d133ee1ce3b118bf5fd022a - Sigstore transparency entry: 1536434528
- Sigstore integration time:
-
Permalink:
semoglou/confinterval@f382134179e121239aed1f7fa3b7d497cea7b444 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/semoglou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f382134179e121239aed1f7fa3b7d497cea7b444 -
Trigger Event:
release
-
Statement type: