Skip to main content

checks.outlier_scores()

Robust z-scores of x’s residuals from an STL decomposition, on its present values.

Usage

Source

checks.outlier_scores(
    x, frequency=None, *, z=4.0, seasonal=13, trend=None, max_iter=20
)

Monthly and quarterly series are decomposed by statsmodels’ STL (seasonal smoother of seasonal years, local-constant); annual series, which have no season, by a lowess trend over trend years (default 21). The residuals are standardised by their median and MAD (1.4826 MAD, the standard deviation for normal residuals). A first, robust fit finds the gross outliers; then each flagged period is replaced by its fitted value and the series decomposed again without robustness weights, until the flagged set is stable, so a spike does not bend the fit around itself (D29). Missing values inside the history are interpolated for the fit and get no score. Raises CheckError when the series has fewer than two years from its first to its last value (seven for annual data).