Bootstrap Confidence Interval Estimate

Estimate confidence intervals using bootstrap resampling for robust statistical inference.

PythonData Integrity

Code

snippet
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)