bbstat


Namebbstat JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA lightweight library for Bayesian bootstrapping and statistical evaluation.
upload_time2025-10-27 12:40:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords bayesian bootstrap statistics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # bbstat

A lightweight library for Bayesian bootstrapping and statistical evaluation.

## Installation

### From PyPI:

```bash
pip install bbstat
```

### From GitHub source code:

```bash
git clone https://github.com/cwehmeyer/bbstat.git
cd bbstat
pip install .
```

## Quickstart

```python
import numpy as np
import bbstat

# 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 estimate of mean income with 87% credibility interval
result = bootstrap(data=income, statistic_fn="median", coverage=0.87, seed=1)
print(result)  # => BootstrapResult(mean=50000.0, ci=(40000.0, 59000.0), coverage=0.87, n_boot=1000)
```

## API Overview

### `bootstrap(data, statistic_fn, coverage=0.87, n_boot=1000, ...)`

Performs Bayesian bootstrapping on input `data` using the given statistic.

- `data`: 1D NumPy array, or tuple/list thereof
- `statistic_fn`: string or callable (e.g., `"mean"`, `"median"`, or custom function)
- `coverage`: credibility interval (default 0.87)
- `n_boot`: number of bootstrap samples
- `seed`: random seed (optional)
- `blocksize`: number of resamples to allocate in one block
- `fn_kwargs`: optional dictionary with parameters for `statistic_fn`

Returns a `BootstrapResult` with:
- `.mean`: estimated statistic value
- `.ci`: tuple representing lower and upper bounds of the credibility interval
- `.coverage`: credibility 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

```python
def custom_statistics(data, weights, *, **kwargs) -> float
```

where `data` is
- a 1D numpy array of length `n_data` or
- 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bbstat",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "bayesian, bootstrap, statistics",
    "author": null,
    "author_email": "Chris Wehmeyer <wehmeyer.chris@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6c/84/d4d4a4d6029f79d5e018b4470d59b13176c1d617fac40737d73269bc77d1/bbstat-0.1.0.tar.gz",
    "platform": null,
    "description": "# bbstat\n\nA lightweight library for Bayesian bootstrapping and statistical evaluation.\n\n## Installation\n\n### From PyPI:\n\n```bash\npip install bbstat\n```\n\n### From GitHub source code:\n\n```bash\ngit clone https://github.com/cwehmeyer/bbstat.git\ncd bbstat\npip install .\n```\n\n## Quickstart\n\n```python\nimport numpy as np\nimport bbstat\n\n# Data preparation: simulated income for a small population (e.g., a survey of 25 people)\nincome = np.array([\n    24_000, 26_000, 28_000, 30_000, 32_000,\n    35_000, 36_000, 38_000, 40_000, 41_000,\n    45_000, 48_000, 50_000, 52_000, 54_000,\n    58_000, 60_000, 62_000, 65_000, 68_000,\n    70_000, 75_000, 80_000, 90_000, 100_000,\n], dtype=np.float64)\n\n# Direct estimate of mean income\nprint(np.mean(income))  # => 52280.0\n\n# Bootstrapped estimate of mean income with 87% credibility interval\nresult = bootstrap(data=income, statistic_fn=\"median\", coverage=0.87, seed=1)\nprint(result)  # => BootstrapResult(mean=50000.0, ci=(40000.0, 59000.0), coverage=0.87, n_boot=1000)\n```\n\n## API Overview\n\n### `bootstrap(data, statistic_fn, coverage=0.87, n_boot=1000, ...)`\n\nPerforms Bayesian bootstrapping on input `data` using the given statistic.\n\n- `data`: 1D NumPy array, or tuple/list thereof\n- `statistic_fn`: string or callable (e.g., `\"mean\"`, `\"median\"`, or custom function)\n- `coverage`: credibility interval (default 0.87)\n- `n_boot`: number of bootstrap samples\n- `seed`: random seed (optional)\n- `blocksize`: number of resamples to allocate in one block\n- `fn_kwargs`: optional dictionary with parameters for `statistic_fn`\n\nReturns a `BootstrapResult` with:\n- `.mean`: estimated statistic value\n- `.ci`: tuple representing lower and upper bounds of the credibility interval\n- `.coverage`: credibility level used\n- `.n_boot`: number of bootstraps performed\n- `.estimates`: array of statistic values computed across the bootstrapped posterior samples\n\n### Weighted statistic functions included\n\nThe module bbstat.statistics provides a number univariate and bivariate weighted statistics:\n- `\"entropy\"`: `bbstat.statistics.compute_weighted_entropy(data, weights)`\n- `\"eta_square_dependency\"`: `bbstat.statistics.compute_weighted_eta_square_dependency(data, weights)`\n- `\"log_odds\"`: `bbstat.statistics.compute_weighted_log_odds(data, weights, state: int)`\n- `\"mean\"`: `bbstat.statistics.compute_weighted_mean(data, weights)`\n- `\"median\"`: `bbstat.statistics.compute_weighted_median(data, weights)`\n- `\"mutual_information\"`: `bbstat.statistics.compute_weighted_mutual_information(data, weights)`\n- `\"pearson_dependence\"`: `bbstat.statistics.compute_weighted_pearson_dependence(data, weights, ddof: int = 0)`\n- `\"percentile\"`: `bbstat.statistics.compute_weighted_percentile(data, weights, percentile: float)`\n- `\"probability\"`: `bbstat.statistics.compute_weighted_probability(data, weights, state: int)`\n- `\"quantile\"`: `bbstat.statistics.compute_weighted_quantile(data, weights, quantile: float)`\n- `\"self_information\"`: `bbstat.statistics.compute_weighted_self_information(data, weights, state: int)`\n- `\"spearman_depedence\"`: `bbstat.statistics.compute_weighted_spearman_depedence(data, weights, ddof: int = 0)`\n- `\"std\"`: `bbstat.statistics.compute_weighted_std(data, weights, ddof: int = 0)`\n- `\"sum\"`: `bbstat.statistics.compute_weighted_sum(data, weights)`\n- `\"variance\"`: `bbstat.statistics.compute_weighted_variance(data, weights, ddof: int = 0)`\n\nIf you want to use your own custom functions, please adhere to this pattern\n\n```python\ndef custom_statistics(data, weights, *, **kwargs) -> float\n```\n\nwhere `data` is\n- a 1D numpy array of length `n_data` or\n- a tuple/list of 1D numpy arrays, each of length `n_data`\n\nand `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`.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A lightweight library for Bayesian bootstrapping and statistical evaluation.",
    "version": "0.1.0",
    "project_urls": {
        "Changelog": "https://github.com/cwehmeyer/bbstat/blob/main/CHANGELOG.md",
        "Documentation": "https://cwehmeyer.github.io/bbstat/",
        "Homepage": "https://github.com/cwehmeyer/bbstat",
        "Issues": "https://github.com/cwehmeyer/bbstat/issues",
        "Repository": "https://github.com/cwehmeyer/bbstat.git"
    },
    "split_keywords": [
        "bayesian",
        " bootstrap",
        " statistics"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "07510bcd9e7fac620d98fccc9184d58da9f5a65b09dac081b8546bcbc171c968",
                "md5": "90f3fa3f9680b110bf9531bc80d711bc",
                "sha256": "7b2b46481c0e386bdb2712e9d9bfb90fa9e8af178546a585109aa2a8e8e9e633"
            },
            "downloads": -1,
            "filename": "bbstat-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "90f3fa3f9680b110bf9531bc80d711bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 20602,
            "upload_time": "2025-10-27T12:40:38",
            "upload_time_iso_8601": "2025-10-27T12:40:38.969789Z",
            "url": "https://files.pythonhosted.org/packages/07/51/0bcd9e7fac620d98fccc9184d58da9f5a65b09dac081b8546bcbc171c968/bbstat-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6c84d4d4a4d6029f79d5e018b4470d59b13176c1d617fac40737d73269bc77d1",
                "md5": "245a887ccbcc73d6f75626900521d3cb",
                "sha256": "5254226637e55d5f1465b6ae7d3e6c2584323329f45681b75cdabcf90c1d9048"
            },
            "downloads": -1,
            "filename": "bbstat-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "245a887ccbcc73d6f75626900521d3cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 27920,
            "upload_time": "2025-10-27T12:40:40",
            "upload_time_iso_8601": "2025-10-27T12:40:40.260856Z",
            "url": "https://files.pythonhosted.org/packages/6c/84/d4d4a4d6029f79d5e018b4470d59b13176c1d617fac40737d73269bc77d1/bbstat-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-27 12:40:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cwehmeyer",
    "github_project": "bbstat",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "bbstat"
}
        
Elapsed time: 1.02403s