Bootmedian
Bootmedian estimates robust statistics (median, mean, sum, std) via bootstrapping and returns confidence intervals for the estimates.
This package provides a small set of utilities centered on the
bootmedian() function in bootmedian/main.py to compute bootstrapped
statistics and an API to run bootstrap-based linear fits.
Highlights
- Robust medians: estimate medians using bootstrap resampling.
- Confidence intervals: returns 1σ, 2σ and 3σ up/down limits for estimates.
- Multiple modes: compute median, mean, std or sum via the
modeargument. - Weighted resampling: supports sample weights in resampling.
Table of Contents
- Overview: short summary and behavior
- Installation: dependencies and install
- Quickstart: minimal usage examples
- API Reference: main functions and parameters
- Notes & Contactn+ Overview
bootmedian() takes a 1-D array-like input and performs nsimul bootstrap
resamples. By default it computes the median of each resample and returns the
median of that distribution together with percentile-based confidence intervals
for 1σ, 2σ and 3σ. NaN values in the input are ignored.
Typical return (dictionary):
median: median of the bootstrap distribution (or mean/std/sum depending onmode).s1_up,s1_down: 1σ upward and downward limits (percentiles).s2_up,s2_down: 2σ limits.s3_up,s3_down: 3σ limits.std1_up,std1_down: optional percentiles of the raw sample (ifstdprovided).sims: the full bootstrap simulation array (useful for diagnostics).
Installation
Requirements: Python 3.8+ and the dependencies listed in setup.py / pyproject.toml.
Install editable (dev) mode from the project root:
pip install -e .
Or install via pip (from PyPI when published):
pip install Bootmedian
Quickstart
Example: compute the bootstrapped median and 1/2/3σ intervals for a sample:
import numpy as np
from bootmedian import bootmedian
data = np.array([1.0, 2.1, 2.3, np.nan, 3.5, 2.0])
result = bootmedian(data, nsimul=2000, errors=1, verbose=True)
print(result)
# -> dict with keys: 'median','s1_up','s1_down',...,'sims'
Using weights:
weights = np.array([1, 1, 2, 1, 1, 1.5])
result_w = bootmedian(data, nsimul=2000, weights=weights)
Change the statistic with mode ("median", "mean", "std", "sum"):
# Bootmedian
Bootmedian estimates robust statistics (median, mean, sum, std) via
bootstrapping and returns confidence intervals for the estimates.
This package provides utilities centered on the `bootmedian()` function in
`bootmedian/bootmedian.py` to compute bootstrapped statistics and an API to run
bootstrap-based linear fits.
Highlights
- Robust medians: estimate medians using bootstrap resampling.
- Confidence intervals: returns 1σ, 2σ and 3σ up/down limits for estimates.
- Multiple modes: compute `median`, `mean`, `std` or `sum` via the `mode` argument.
- Weighted resampling: supports sample weights in resampling.
Table of contents
- Overview
- Installation
- Quickstart
- API reference
- Notes & contact
Overview
`bootmedian()` takes a 1-D array-like input and performs `nsimul` bootstrap
resamples. By default it computes the median of each resample and returns the
median of that distribution together with percentile-based confidence intervals
for 1σ, 2σ and 3σ. NaN values in the input are ignored.
Typical return (dictionary)
- `median`: median of the bootstrap distribution (or mean/std/sum depending on `mode`).
- `s1_up`, `s1_down`: 1σ upward and downward limits (percentiles).
- `s2_up`, `s2_down`: 2σ limits.
- `s3_up`, `s3_down`: 3σ limits.
- `std1_up`, `std1_down`: optional percentiles of the raw sample (if `std` provided).
- `sims`: the full bootstrap simulation array (useful for diagnostics).
Installation
Requirements: Python 3.8+ and the dependencies listed in `setup.py` / `pyproject.toml`.
Install in editable (development) mode from the project root:
```bash
pip install -e .
Quickstart
Example: compute the bootstrapped median and 1/2/3σ intervals for a sample:
import numpy as np
from bootmedian import bootmedian
data = np.array([1.0, 2.1, 2.3, np.nan, 3.5, 2.0])
result = bootmedian(data, nsimul=2000, errors=1, verbose=True)
print(result)
# -> dict with keys: 'median','s1_up','s1_down',...,'sims'
Using weights:
weights = np.array([1, 1, 2, 1, 1, 1.5])
result_w = bootmedian(data, nsimul=2000, weights=weights)
Change the statistic with mode ("median", "mean", "std", "sum"):
mean_result = bootmedian(data, nsimul=1500, mode="mean")
Bootstrap linear fit
Use bootfit(x, y, nsimul) to obtain bootstrap distributions for slope
(m) and intercept (b). The function returns a dictionary with medians and
confidence percentiles for m and b.
from bootmedian import bootfit
x = np.linspace(0, 10, 20)
y = 2.3*x + 1.5 + np.random.normal(scale=0.5, size=x.size)
fit = bootfit(x, y, nsimul=1000)
print(fit['m_median'], fit['b_median'])
API reference (short)
bootstrap_resample(X, weights=False, seed=None)— Resamples an array-likeXwith optionalweights(weighted sampling). Returns a flattened numpy array with one bootstrap resample.median_bootstrap(argument)/mean_bootstrap(argument)/sum_bootstrap(argument)/std_bootstrap(argument)— Internal helpers used bybootmedianwhen running parallel workers.argumentis a tuple/list:(sample, weights, std)wherestdis optional.boot_polyfit(x, y, seed)— Performs a single resampled linear fit and returns[slope, intercept].bootfit(x, y, nsimul, errors=1)— Runsnsimulbootstrap fits (currently single-threaded loop with progress). Returns a dict with medians and percentile confidence intervals formandb.bootmedian(sample_input, nsimul=1000, weights=False, errors=1, std=False, verbose=False, nthreads=7, mode="median")— Main function; see docstring in code for parameter details.
Notes & recommendations
- The implementation uses
bottleneckandpandas.DataFrame.samplefor resampling. - For reproducibility you can set
numpy.random.seed(...)before calling routines that internally use randomness. Some helper functions accept aseed. nsimulcontrols accuracy vs runtime: start with a few hundred simulations, then increase to a few thousand if you need tighter percentiles.- If your input contains many NaNs ensure weights (if provided) align with non-NaN entries.
Development & tests
- See
setup.pyandpyproject.tomlfor declared dependencies. - A small example is available at
examples/simple_example.py— run it after installing dependencies withpip install -e ..
License & contact
This project is released under the BSD license (see setup.py for metadata).
Author: Alejandro S. Borlaff a.s.borlaff@nasa.gov
Metadata
Release files for Bootmedian 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bootmedian-1.1.3.tar.gz | 7.8 kB | Without provenance | Details for bootmedian-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bootmedian-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for bootmedian-1.1.3-py3-none-any.whl |
Total release size: 15.5 kB
Release files / bootmedian-1.1.3.tar.gz
| Download URL | bootmedian-1.1.3.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
232503ec3d09fd5dc16450613864d09671515a66d7ea870bc6eeedd23bf9be1f
|
|
BLAKE2b-256 checksum How to use checksums |
41ec4aa54d0cfe0984cfe71babc5344e05ef7022bd872d14cb6fa233934dfb91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / bootmedian-1.1.3-py3-none-any.whl
| Download URL | bootmedian-1.1.3-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ca21d23b56cb442f74c3a685411560897fff1cb638c200c611a522dda6d77096
|
|
BLAKE2b-256 checksum How to use checksums |
83a989f9eb233361ee9a40e5219cd612d677fa246b6e866b430f74541d881e49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for Bootmedian 1.1.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.