A software to estimate medians through Bootstrapping
Project description
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
If you'd like, I can add a short examples/ notebook or a requirements.txt and run a quick sanity test to confirm imports.
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 bootmedian-1.1.2.tar.gz.
File metadata
- Download URL: bootmedian-1.1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f9fe29871bc801919d979c9e4971827953d2fb3918614d68eb00c7494b16d57
|
|
| MD5 |
716da1500032344d16e64f69569bd912
|
|
| BLAKE2b-256 |
70703ad916fcdd6e0d9032a3c1534de6d81993602670c7692b3b33aff5859cc6
|
File details
Details for the file bootmedian-1.1.2-py3-none-any.whl.
File metadata
- Download URL: bootmedian-1.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
babd19147ebcd9ea2dfc5c9b0395f5635e3df9938a58967f3bbaa2ec5d0eac9e
|
|
| MD5 |
e77142ccbad6f68217d40f2c52e0eac7
|
|
| BLAKE2b-256 |
33682c0c5c697eef8c5ecbe954e4122c5b7341512775564a9f378f807046db17
|