Generate sample data with heavy-tailed Cauchy noise (outliers)
np.random.seed(42)
clean_data = np.random.normal(loc=10.0, scale=2.0, size=200)
outliers = np.random.cauchy(loc=10.0, scale=50.0, size=20)
y = np.concatenate([clean_data, outliers])
1. Adaptive robust center estimation using Huber M-estimator
Threshold epsilon adapts to sample scale via MAD (Median Absolute Deviation)
mad = np.median(np.abs(y - np.median(y)))
huber = HuberRegressor(epsilon=1.35, alpha=0.0)
huber.fit(np.ones((len(y), 1)), y)
robust_mean = huber.intercept_
2. Non-parametric bootstrapped Adaptive Confidence Interval
boot_means = []
for _ in range(1000):
boot_sample = np.random.choice(y, size=len(y), replace=True)
h_boot = HuberRegressor(epsilon=1.35, alpha=0.0)
h_boot.fit(np.ones((len(boot_sample), 1)), boot_sample)
boot_means.append(h_boot.intercept_)
ci_lower, ci_upper = np.percentile(boot_means, [2.5, 97.5])
print(f"Robust Point Estimate: {robust_mean:.3f}")
print(f"95% Adaptive Robust CI: [{ci_lower:.3f}, {ci_upper:.3f}]")Key Takeaway: Adaptive robust confidence intervals provide valid statistical coverage and high efficiency by dynamically tuning truncation parameters according to the empirical distribution, offering essential protection against heavy tails and extreme data corruption.
Robust Statistics & Adaptive Inference