Bootstrap Confidence Interval Estimate
Estimate confidence intervals using bootstrap resampling for robust statistical inference.
Code
import numpy as np
def bootstrap_ci(data, statistic=np.mean, n_boot=10000, ci=0.95):
boots = [statistic(np.random.choice(data, size=len(data), replace=True)) for _ in range(n_boot)]
lower = np.percentile(boots, (1 - ci) / 2 * 100)
upper = np.percentile(boots, (1 + ci) / 2 * 100)
return lower, upper
def bootstrap_mean(data, n_boot=10000):
return bootstrap_ci(data, np.mean, n_boot)Report a problem with this exampleOpens a pre-filled issue on GitHub.