bbstat
A lightweight library for Bayesian bootstrapping and statistical evaluation.
Installation
From PyPI:
pip install bbstat
From GitHub source code:
git clone https://github.com/cwehmeyer/bbstat.git
cd bbstat
pip install .
Quickstart
import numpy as np
from bbstat import bootstrap
# Data preparation: simulated income for a small population (e.g., a survey of 25 people)
income = np.array([
24_000, 26_000, 28_000, 30_000, 32_000,
35_000, 36_000, 38_000, 40_000, 41_000,
45_000, 48_000, 50_000, 52_000, 54_000,
58_000, 60_000, 62_000, 65_000, 68_000,
70_000, 75_000, 80_000, 90_000, 100_000,
], dtype=np.float64)
# Direct estimate of mean income
print(np.mean(income)) # => 52280.0
# Bootstrapped distribution of the mean income.
distribution = bootstrap(data=income, statistic_fn="mean", seed=1)
print(distribution) # => BootstrapDistribution(mean=52263.8..., size=1000)
# Summarize the bootstrapped distribution of the mean income.
summary = distribution.summarize(level=0.87)
print(summary) # => BootstrapSummary(mean=52263.8..., ci_low=46566.8..., ci_high=58453.6..., level=0.87)
print(summary.round()) # => BootstrapSummary(mean=52000.0, ci_low=47000.0, ci_high=58000.0, level=0.87)
API Overview
bootstrap(data, statistic_fn, n_boot=1000, ...)
Performs Bayesian bootstrapping on input data using the given statistic.
data: 1D NumPy array, or tuple/list thereofstatistic_fn: string or callable (e.g.,"mean","median", or custom function)level: credible interval (default 0.87)n_boot: number of bootstrap samplesseed: random seed (optional)blocksize: number of resamples to allocate in one blockfn_kwargs: optional dictionary with parameters forstatistic_fn
Returns a BootstrapResult with:
.mean: estimated statistic value.ci: tuple representing lower and upper bounds of the credible interval.level: credible level used.n_boot: number of bootstraps performed.estimates: array of statistic values computed across the bootstrapped posterior samples
Weighted statistic functions included
The module bbstat.statistics provides a number univariate and bivariate weighted statistics:
"entropy":bbstat.statistics.compute_weighted_entropy(data, weights)"eta_square_dependency":bbstat.statistics.compute_weighted_eta_square_dependency(data, weights)"log_odds":bbstat.statistics.compute_weighted_log_odds(data, weights, state: int)"mean":bbstat.statistics.compute_weighted_mean(data, weights)"median":bbstat.statistics.compute_weighted_median(data, weights)"mutual_information":bbstat.statistics.compute_weighted_mutual_information(data, weights)"pearson_dependence":bbstat.statistics.compute_weighted_pearson_dependence(data, weights, ddof: int = 0)"percentile":bbstat.statistics.compute_weighted_percentile(data, weights, percentile: float)"probability":bbstat.statistics.compute_weighted_probability(data, weights, state: int)"quantile":bbstat.statistics.compute_weighted_quantile(data, weights, quantile: float)"self_information":bbstat.statistics.compute_weighted_self_information(data, weights, state: int)"spearman_depedence":bbstat.statistics.compute_weighted_spearman_depedence(data, weights, ddof: int = 0)"std":bbstat.statistics.compute_weighted_std(data, weights, ddof: int = 0)"sum":bbstat.statistics.compute_weighted_sum(data, weights)"variance":bbstat.statistics.compute_weighted_variance(data, weights, ddof: int = 0)
If you want to use your own custom functions, please adhere to this pattern
def custom_statistic(data, weights, *, **kwargs) -> float
where data is
- a 1D numpy array of length
n_dataor - a tuple/list of 1D numpy arrays, each of length
n_data
and weights is a 1D numpy array of length n_data, with non-negative elements that sum up to one. The function may also take additional parameters which can be supplied via **kwargs.
License
This project is licensed under the MIT License.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
Metadata
Release files for bbstat 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bbstat-0.1.1.tar.gz | 31.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bbstat-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.3 kB
Release files / bbstat-0.1.1.tar.gz
| Download URL | bbstat-0.1.1.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d157bbcd2bdc7174b400b67a15e8820a951b53b395e364fd86f6e2a2f9bc521
|
|
BLAKE2b-256 checksum How to use checksums |
bfcbce97bf02b0d22ca898d5b3c35c906bbce186c7c8c3e827c17a5612539652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2025.
Transparency logRelease files / bbstat-0.1.1-py3-none-any.whl
| Download URL | bbstat-0.1.1-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
841bbfa4dab0eb78f3b39a7b6747cffc73ff88318308a4121185a9adad91699d
|
|
BLAKE2b-256 checksum How to use checksums |
a273c54ed76ad16397d0c9f9afd503974c2673908455641e1de19676710c1083
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2025.
Transparency log