Estimate uncertainty with confidence intervals

Interpret a confidence interval and bootstrap a statistic when resampling matches the data design.

On this page

Read a 95 percent confidence interval

Under its assumptions, a 95 percent confidence-interval procedure captures the fixed population parameter in about 95 percent of repeated samples. A confidence interval for a mean describes uncertainty about the mean. Predicting individual future values needs a different interval.

Bootstrap the mean of independent observations

A bootstrap draws samples with replacement and recalculates the statistic. This example uses a percentile interval and a fixed random seed. Match the resampling unit to the design, especially with repeated orders, clustered users, or time series.

import numpy as np
from scipy.stats import bootstrap

units = np.array([8, 10, 12, 14, 16, 18])
result = bootstrap((units,), np.mean, confidence_level=0.95, method="percentile",
                   n_resamples=4_999, rng=np.random.default_rng(42))
low, high = result.confidence_interval
print(f"Mean: {units.mean():.1f}")
print(f"95% CI: {low:.2f} to {high:.2f}")
Example output
Mean: 13.0
95% CI: 10.33 to 15.67

Official references