series 1: mean=3.00, std=2.00
series 2: mean=10.71, std=20.18
On the other hand, the median and IQR are robust:
from scipy.stats import iqrprint(f"series 1: median={np.median(series1):.2f}, IQR={iqr(series1):.2f}")print(f"series 2: median={np.median(series2):.2f}, IQR={iqr(series2):.2f}")
series 1: median=3.00, IQR=3.00
series 2: median=3.00, IQR=3.00
19.1 MAD
Another rubust method is MAD, the Median Absolute Deviation, given by
MAD=median(∣xi−median(x)∣),
where ∣⋅∣ is the absolute value.
Applying MAD to the stationary time series from before, yields
Here, the threshold is the median ±3k⋅ MAD, where the value k=1.4826 scales MAD so that when the data is gaussianly distributed, 3k equals 1 standard deviation.