In SciPy, the right confidence-interval function depends on what you are estimating: an arbitrary statistic, a binomial success proportion, or an empirical distribution function. This guide covers nine documented approaches across those targets, plus the related APIs for a difference in means and distribution intervals. They are not interchangeable, and SciPy does not define an official set of “nine methods.”
Choose an interval for the quantity you want to estimate
Before writing code, identify the estimand—the population quantity your interval is intended to cover. A mean, a binomial proportion, and an empirical CDF value require different methods and APIs. The nine approaches below are a practical grouping of methods in the SciPy 1.18.0 documentation, not a formal SciPy taxonomy.
As an Amazon Associate I earn from qualifying purchases.
- Any statistic calculated from sample data: use
scipy.stats.bootstrap. - Success probability from a binomial count: use
binomtest(...).proportion_ci(). - Empirical CDF or survival-function estimate: use the empirical distribution function’s
confidence_interval().
For independent samples and a difference in population means, ttest_ind provides a separate result-based interval. By contrast, binom.interval and t.interval describe intervals in a specified random variable’s distribution, not confidence intervals for unknown parameters.
Three bootstrap methods for an arbitrary statistic
Bootstrap intervals resample the observed data with replacement, calculate a statistic for each resample, then use the resulting bootstrap distribution to construct bounds. They are useful when the target is a statistic that does not have a dedicated SciPy interval API. The method names and behavior below follow the SciPy bootstrap reference.
#1 Best Overall
1. Percentile bootstrap
The percentile method takes quantiles of the bootstrap distribution as the interval endpoints. It is intuitive, although SciPy characterizes it as rarely used in practice. Choose it explicitly with method="percentile" when that construction suits your analysis.
2. Basic (reverse percentile) bootstrap
The basic method is a common alternative to the percentile method. Select it with method="basic". Both methods use bootstrap resamples, but they construct bounds differently; do not treat the method choice as merely a change in label.
3. BCa bootstrap
BCa means bias-corrected and accelerated. SciPy uses it as the default bootstrap method, but a degenerate bootstrap distribution can produce NaN interval endpoints. If that happens, examine whether the data or statistic leaves too little variation for resampling to work, rather than reporting the bounds as if they were valid.
Rank #2
Example: interval for a sample mean
This example estimates the population mean from one sample. It fixes the method, confidence level, resample count, and random-number generator so the run is reproducible for the same data and software environment.
import numpy as np
import scipy
from scipy import stats
x = np.array([4.2, 5.1, 3.8, 6.0, 4.7, 5.5])
rng = np.random.default_rng(2026)
result = stats.bootstrap(
(x,),
np.mean,
confidence_level=0.95,
n_resamples=9999,
method="BCa",
rng=rng,
)
print("SciPy version:", scipy.__version__)
print("95% CI for the population mean:", result.confidence_interval)
The installed version matters: this example follows the SciPy 1.18.0 reference, whose signature documents 9,999 resamples and BCa as defaults. Specifying them makes the choices visible. A fixed RNG seed supports reproducibility, but does not guarantee identical output across different SciPy or NumPy versions.
Paired versus independent samples
For paired observations, pass the samples to the statistic in corresponding order and set paired=True. SciPy then resamples shared indices, preserving each pair. With the default independent resampling, each sample is resampled separately; use that design when the samples are independent, not when observations are matched.
Three methods for a binomial success proportion
When the data are a count of successes k in n binomial trials, the target is the underlying success proportion. SciPy exposes three methods through binomtest(k, n).proportion_ci(); the SciPy 1.18.0 reference documents exact as the default.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
4. Exact Clopper–Pearson
Use method="exact" for the Clopper–Pearson interval. It is the default, but that does not establish it as universally preferable for every analysis.
5. Wilson score
Use method="wilson" for the Wilson score interval.
6. Wilson with continuity correction
Use method="wilsoncc" for the Wilson interval with continuity correction.
Example: compare the available proportion intervals
Here k is the observed number of successes and n is the number of trials. Each result is an interval for the binomial success proportion, not for a sample mean.
from scipy.stats import binomtest
k, n = 42, 60
result = binomtest(k, n)
for method in ("exact", "wilson", "wilsoncc"):
ci = result.proportion_ci(confidence_level=0.95, method=method)
print(method, ci)
SciPy’s API documentation identifies the supported constructions and cites their source papers, but does not establish a universal performance ranking among them. Make the selected method explicit when reporting results.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Two intervals for an empirical CDF or survival function
An empirical distribution function estimates a CDF or survival-function value from observed data. Its confidence interval is a specialized choice for that estimate, rather than a general-purpose interval for any statistic. SciPy documents two methods in its empirical distribution function reference.
Best Value
7. Greenwood linear interval
method="linear" selects the conventional Greenwood interval and is the documented default.
8. Exponential Greenwood (log-log) interval
method="log-log" selects the exponential Greenwood, or log-log, interval. SciPy clips the conventional Greenwood bounds to the unit interval, [0, 1]. Either method can produce NaN endpoints, so inspect the result rather than assuming every dataset yields finite bounds.
Example: request a log-log interval
After constructing an empirical distribution function, specify the point at which to evaluate it and the desired method:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →from scipy.stats import ecdf
sample = [1, 2, 2, 3, 4, 5]
res = ecdf(sample)
ci = res.cdf.confidence_interval(
confidence_level=0.95,
method="log-log",
)
print(ci)
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When SciPy returns an interval that is not a confidence interval for an unknown parameter
The word “interval” appears in other SciPy APIs, but those results answer a different question. The binomial distribution and Student’s t distribution each provide an interval method. These return equal-area intervals around the median of the specified random variable. They are distribution intervals, not confidence intervals for an unknown parameter estimated from a sample.
For a confidence interval around the difference between independent population means, use the interval attached to the test result instead. The ttest_ind reference documents confidence_interval() on the result object; this capability was added in SciPy 1.11.0.
from scipy import stats
x = [12, 15, 14, 10, 13]
y = [9, 11, 8, 12, 10]
result = stats.ttest_ind(x, y, equal_var=True)
ci = result.confidence_interval(confidence_level=0.95)
print("95% CI for the difference in population means:", ci)
This test-result interval concerns the difference in population means. Set the test’s variance assumption to match the analysis; the example uses the equal-variance setting.
Quick Recap
A practical method-selection checklist
- Write down the target quantity first: mean, difference in means, proportion, arbitrary statistic, or CDF/SF value.
- Match the sampling design: use paired bootstrap resampling for matched observations and independent resampling for independent samples.
- For proportions, name the exact, Wilson, or continuity-corrected Wilson construction in your report.
- For bootstrap intervals, record the method, confidence level, resample count, RNG setup, and SciPy version.
- Check endpoints for NaNs, especially with BCa bootstrap and empirical distribution function intervals.
- Do not interpret
binom.intervalort.intervalas confidence intervals for parameters inferred from observed data.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




