Nonparametric uncertainty estimation
Estimate uncertainty for a sample mean, median, percentile, or another statistic without assuming a parametric distribution.
SciPy · Function
Computes a bootstrap confidence interval for a statistic by repeatedly resampling input data with replacement. The default BCa method can account for bias and skew in the bootstrap distribution.
The function repeatedly samples each input with replacement, evaluates the statistic on every resample, and uses the resulting bootstrap distribution to construct a confidence interval. Its default BCa method adjusts the interval using bias and acceleration; percentile and basic methods are also available.
scipy.stats.bootstrap(data, statistic, *, n_resamples=9999, batch=None, vectorized=None, paired=False, axis=0, confidence_level=0.95, alternative='two-sided', method='BCa', bootstrap_result=None, rng=None, random_state=None)| Name | Type | Description |
|---|---|---|
data | tuple of array-like | Tuple of sample arrays containing the observations to resample. |
statistic | callable | Callable that computes the statistic from one or more samples. |
n_resamples | int | Number of bootstrap resamples; default 9999. |
batch | int or None | Number of resamples processed in a batch; default None. |
vectorized | bool or None | Whether statistic supports vectorized evaluation; default None infers this. |
paired | bool | Whether input samples are paired and must use shared resample indices. |
axis | int | Axis along which observations are arranged; default 0. |
confidence_level | float | Confidence level between 0 and 1; default 0.95. |
alternative | {'two-sided', 'less', 'greater'} | Interval alternative: 'two-sided', 'less', or 'greater'. |
method | {'BCa', 'percentile', 'basic'} | Interval construction method: 'BCa', 'percentile', or 'basic'. |
bootstrap_result | BootstrapResult or None | Previously computed BootstrapResult whose resamples may be reused. |
rng | numpy.random.Generator or seed-like | Random-number Generator or seed specification. |
A BootstrapResult containing confidence_interval, standard_error, and the bootstrap distribution.
import numpy as np
from scipy.stats import bootstrap
rng = np.random.default_rng(42)
data = (rng.normal(size=30),)
result = bootstrap(data, np.mean, rng=rng)
print(result.confidence_interval.low)
print(result.confidence_interval.high)Computes a reproducible 95% BCa confidence interval for the sample mean.
Estimate uncertainty for a sample mean, median, percentile, or another statistic without assuming a parametric distribution.
Quantify uncertainty for a statistic computed from matched observations in multiple arrays.
Reuse bootstrap work or tune batch processing when running many resamples or large arrays.
It generates resamples with replacement, evaluates the statistic for each resample, and derives a confidence interval from the resulting distribution. The default interval method is BCa.
Follow-up: How can repeated calls be made reproducible? Pass a seeded NumPy Generator through rng.
The data argument is a tuple of sample arrays, while statistic is the callable evaluated on each resample. The callable can operate on one or multiple samples, depending on the statistic and paired setting.
Follow-up: When should paired=True be used? Use it when corresponding observations in separate samples must be resampled together.
n_resamples controls the number of bootstrap replicates and defaults to 9999. batch controls how many resamples are processed together, allowing memory use to be managed.
Follow-up: What is the trade-off of reducing batch? It lowers peak memory consumption but may increase execution overhead.
scipy.stats.bootstrap.BootstrapResultscipy.stats.confidence_interval