Written and maintained by CASRAI Editorial Board
Published
On this page
Outlier detection in time series is the statistical identification of observations, structural shifts, or sequence patterns that deviate significantly from the temporal trajectory, seasonal cycles, or autocorrelation structure of sequential data. Unlike standard tabular outlier analysis that treats observations as independent and identically distributed, time series outlier detection explicitly isolates anomalous shocks from legitimate seasonal peaks, structural trends, and autoregressive noise using decomposition techniques, robust rolling estimators, and dynamic ARIMA residual modeling.
Definition and Core Concepts in Time Series Outlier Detection
In quantitative research and longitudinal analysis, time series data consist of observations indexed in chronological order, denoted as yt for t = 1, 2, …, N. Observations within a time series exhibit temporal dependency, meaning that the value at time t is statistically correlated with preceding values yt-1, yt-2, and so forth. Because of this serial dependency, an extreme value cannot be judged in isolation. An observation that appears standard relative to the overall sample mean may be an extreme anomaly if it occurs during a seasonal trough. Time series outlier detection classifies anomalies into point outliers (single unexpected spikes), contextual outliers (values anomalous within a specific temporal window), and collective outliers (subsequences showing abnormal patterns over time). Classical sample variances and ordinary least squares estimators possess a 0% breakdown point, meaning that a single unmodeled shock can distort parameter estimates and inflate residual variance. When working in computational environments, researchers integrate these diagnostic workflows alongside general outlier detection workflows in Python to ensure robust data pre-processing.
Typology of Time Series Outliers: AO, LS, TC, and IO
Formal time series methodology distinguishes between four structural outlier mechanisms codified by Box, Tiao, Fox, Tsay, and Chen and Liu, and standardized in the U.S. Census Bureau X-13ARIMA-SEATS seasonal adjustment engine and Eurostat seasonal adjustment guidelines:
- Additive Outlier (AO): An isolated exogenous shock affecting only observation yt0 at timestamp t0 without lingering impact on future observations: yt = xt + ω × It(t0), where xt is the uncorrupted process, ω is the shock magnitude, and It(t0) is an indicator equal to 1 at t = t0 and 0 otherwise. Typical causes include data recording errors or momentary equipment dropouts.
- Level Shift (LS): An abrupt, permanent step change in the series mean baseline starting at timestamp t0 and persisting indefinitely: yt = xt + (ω / (1 – B)) × It(t0), where B is the backshift operator (B yt = yt-1). Level shifts reflect structural changes such as regulatory revisions or sensor recalibrations.
- Temporary Change (TC): An instantaneous shock at t0 that decays exponentially back toward baseline: yt = xt + (ω / (1 – δB)) × It(t0), where δ is a decay parameter satisfying 0 < δ < 1 (standardized to δ = 0.7 in X-13ARIMA-SEATS). Temporary changes model transient disruptions such as labor strikes or adverse weather events.
- Innovational Outlier (IO): An anomalous shock that enters the innovation white-noise process at at t0 and propagates dynamically through the moving-average filter weights ψ(B) of the time series model: yt = xt + (θ(B) / φ(B)) × ω × It(t0). In stationary autoregressive models, the shock dissipates according to system dynamics, whereas in integrated non-stationary processes, an innovational shock permanently alters both level and trajectory.
Formula and Mathematical Derivation with Every Symbol Explained
Time series outlier detection techniques generally operate under two mathematical paradigms: robust nonparametric local window filtering or model-based residual diagnostics.
The Hampel Identifier (Rolling MAD)
The Hampel identifier is a robust local filtering technique designed to detect point anomalies in sequential data. For a time series yt, a symmetric sliding window of bandwidth k (total span 2k + 1) centered at timestamp t is constructed. The local median Mt across the window is defined as:
Mt = median(yt-k, yt-k+1, …, yt, …, yt+k-1, yt+k)
where Mt represents the robust measure of local central tendency. To quantify dispersion without sensitivity to extreme values, the median absolute deviation (MAD) is computed over the same window:
MADt = median(|yt-k – Mt|, |yt-k+1 – Mt|, …, |yt+k – Mt|)
Because raw MAD estimates the 75th percentile of a half-normal distribution, it is scaled by a factor of 1.4826 (derived from 1 / Φ-1(0.75), where Φ is the standard normal cumulative distribution function) to achieve asymptotic consistency with the standard deviation σ under Gaussian assumptions. The scaled local dispersion estimator St is:
St = 1.4826 × MADt
The standardized Hampel test statistic ZH,t is evaluated against a decision threshold c (conventionally set to c = 3.0, representing an empirical 99.73% normal confidence interval):
ZH,t = |yt – Mt| / St
If ZH,t > c, the observation yt is flagged as an outlier. Both the median and MAD possess a 50% breakdown point, ensuring that up to k observations in the local window can be corrupted without biasing the detection threshold.
STL Decomposition Residual Screening
When time series exhibit trend and seasonality, Seasonal-Trend decomposition using Loess (STL) partitions the additive series into three components:
Yt = Tt + St + Rt
where Yt is the observed measurement, Tt is the smooth trend-cycle component, St is the seasonal pattern, and Rt is the remainder residual. Robust STL applies Cleveland’s bisquare weighting iterations to downweight extreme residual points, preventing outliers from distorting Tt and St. Outlier detection is then applied to the remainder series Rt via modified Z-scores:
MR,t = 0.6745 × |Rt – median(R)| / MAD(R)
Observations with MR,t > 3.5 are flagged as anomalies without risk of false positives from regular seasonal cycles.
ARIMA Dynamic Residual Test Statistics
In parametric modeling, outliers are evaluated by fitting an autoregressive integrated moving average (ARIMA) model and inspecting the one-step-ahead standardized residuals et:
τt = et / (σ̂a × √(κt))
where et = yt – ŷt|t-1 is the prediction error, σ̂a is the estimated innovation standard deviation, and κt is a variance ratio adjustment factor. The maximum absolute statistic max(|τt|) is compared against a sample-size adjusted critical value cN (typically 3.5 to 4.0). Analysts must verify autocorrelation in time series data, as unmodeled autocorrelation distorts residual test statistics.
Worked Example with Real Numbers and Step-by-Step Arithmetic
To illustrate the exact arithmetic of time series outlier detection, consider an empirical sequence of N = 10 daily industrial sensor measurements collected at 24-hour intervals. The recorded values (in degrees Celsius) are:
y = [20.2, 20.5, 20.1, 20.4, 28.6, 20.3, 20.6, 20.2, 20.5, 20.4]
An apparent temperature spike of 28.6 °C occurs at timestamp t = 5. We evaluate t = 5 using a two-sided Hampel filter with window half-width k = 2 (total window span 2k + 1 = 5 observations) and threshold c = 3.0.
- Extract the local window: For t = 5, the window spans timestamps t = 3, 4, 5, 6, and 7:
W5 = [20.1, 20.4, 28.6, 20.3, 20.6]. - Compute the local window median (M5): Sort the five values in ascending order:
Wsorted = [20.1, 20.3, 20.4, 20.6, 28.6].
With n = 5, the median is the third element:
M5 = 20.4 °C. - Calculate absolute deviations from the median: Subtract M5 = 20.4 from each observation in W5:
|20.1 – 20.4| = 0.3 °C
|20.4 – 20.4| = 0.0 °C
|28.6 – 20.4| = 8.2 °C
|20.3 – 20.4| = 0.1 °C
|20.6 – 20.4| = 0.2 °C. - Compute the raw Median Absolute Deviation (MAD5): Sort the absolute deviations in ascending order:
Dsorted = [0.0, 0.1, 0.2, 0.3, 8.2].
The median of these deviations is the third value:
MAD5 = 0.2 °C. - Calculate the scaled dispersion estimator (S5): Multiply by the normal consistency factor 1.4826:
S5 = 1.4826 × 0.2 = 0.29652 °C. - Determine the critical decision threshold: Multiply scaled dispersion by c = 3.0:
Threshold = 3.0 × S5 = 3.0 × 0.29652 = 0.88956 °C. - Compute test statistic and evaluate: Calculate the standardized Hampel ratio for y5 = 28.6 °C:
Deviation = |28.6 – 20.4| = 8.2 °C
ZH,5 = 8.2 / 0.29652 = 27.654.
Because ZH,5 = 27.654 exceeds c = 3.0 (and the 8.2 °C deviation exceeds 0.88956 °C), the observation at t = 5 is conclusively flagged as an outlier.
By contrast, applying classical non-robust mean and standard deviation to W5 yields a sample mean of 22.0 °C and standard deviation of 3.694 °C. The classical Z-score for y5 is (28.6 – 22.0) / 3.694 = 1.787. Because 1.787 is below the standard 3.0 threshold, non-robust screening fails completely due to outlier masking, where the outlier inflates the variance to hide its own presence.
Interpretation and Diagnostic Decision Guidance
Identifying an outlier is the first analytical step; researchers must subsequently interpret its structural typology to determine appropriate analytical remediation. The table below summarizes diagnostic reading guidance:
| Diagnostic Result | Statistical Signature | Underlying Mechanism | Recommended Analytical Action |
|---|---|---|---|
| Additive Outlier (AO) | Single isolated timestamp ZH,t > 3.0; adjacent residuals immediately return to baseline. | Sensor transmission error, typographical glitch, or momentary external pulse. | Interpolate via local median or model using an impulse dummy indicator in regression. |
| Level Shift (LS) | Residuals exhibit sustained sign bias (+ or -) across multiple consecutive timestamps post t0. | Permanent baseline shift from policy reforms, structural breaks, or hardware recalibration. | Incorporate a step intervention regressor (1 / (1 – B)) or apply first-order differencing. |
| Temporary Change (TC) | Large initial spike at t0 followed by exponential decay across subsequent lags. | Transitory disruption with prolonged recovery, such as supply shocks or extreme weather. | Fit a transient transfer function regressor with decay parameter δ ≈ 0.7. |
| Innovational Outlier (IO) | Residual shock propagates through estimated autocorrelation functions (ACF/PACF). | Internal structural shock entering the white-noise generating process. | Re-estimate autoregressive polynomials or employ robust Kalman filtering. |
| Variance Burst | Multiple clustered residual spikes with alternating signs but constant mean level. | Heteroskedastic regime shift or turbulent market volatility. | Transition to Generalized Autoregressive Conditional Heteroskedasticity (GARCH) modeling. |
When estimating dynamic parameters, researchers cross-reference these interpretations when constructing ARIMA models for research time series to ensure interventions are modeled explicitly.
Assumptions and Common Mistakes
Valid implementation of time series outlier detection requires adherence to several methodological assumptions:
- Assuming Independence of Observations: Applying cross-sectional outlier screening methods directly to time series data assumes independent and identically distributed errors. Autocorrelation violates this assumption, producing widespread false-positive flags during seasonal crests. For univariate exploratory rules, review calculating interquartile range fences.
- Deleting Observations Instead of Modeling Them: Dropping timestamps creates irregular temporal intervals, breaking lag operators and invalidating autoregressive models. Anomalies should be modeled via intervention variables or imputed using Kalman smoothing.
- Neglecting Trend and Seasonality: Applying symmetric rolling windows to strongly trending data introduces severe phase lag into median estimates. Time series with pronounced trends should be detrended or decomposed via STL prior to residual evaluation.
- Outlier Masking and Swamping: Relying on sample mean and standard deviation causes multiple outliers to mask each other or swamp normal observations. Estimators with a 50% breakdown point, such as the MAD, prevent masking and swamping.
- Confusing Level Shifts with Point Outliers: When a permanent regime shift occurs, treating the initial observation as an isolated additive outlier leads to misaligned subsequent forecasts. Analysts must verify whether post-shock observations remain elevated.
How to Report Time Series Outlier Detection in APA 7th Style
Academic manuscripts reporting time series data screening should state the detection algorithm, bandwidth parameters, decision thresholds, detected anomaly typologies, and handling strategy. Below is an APA 7th reporting template:
“Prior to time series modeling, the daily sensor temperature series (N = 10 observations) was screened for anomalous observations and structural shocks using a two-sided Hampel identifier with a window bandwidth of k = 2 (total span = 5 observations) and a conservative decision threshold of 3.0 scaled median absolute deviations (S5 = 0.30 °C). One severe additive outlier was identified at timestamp t = 5 (y5 = 28.60 °C, absolute deviation = 8.20 °C, ZH = 27.65), significantly exceeding the critical threshold of 0.89 °C. Sensitivity analysis demonstrated that this single shock distorted the unadjusted sample mean from 20.36 °C to 22.00 °C and inflated the sample standard deviation from 0.18 °C to 3.69 °C. Following Box-Jenkins diagnostic conventions, the observation was retained and modeled via an impulse intervention indicator variable (AO) during subsequent ARIMA parameter estimation, preserving the temporal continuity of the sequence.”
How to Calculate Time Series Outliers in Python, R, and Excel
Time series outlier screening can be executed across standard computational platforms using the following tested snippets.
Python Implementation (SciPy and NumPy)
In Python, the Hampel filter evaluates rolling windows and calculates scaled MAD values:
import numpy as np
from scipy.signal import medfilt
def hampel_filter(data, k=2, threshold=3.0):
n = len(data)
flags = np.zeros(n, dtype=bool)
rolling_med = medfilt(data, kernel_size=2*k+1)
for i in range(n):
start = max(0, i - k)
end = min(n, i + k + 1)
window = data[start:end]
local_mad = 1.4826 * np.median(np.abs(window - np.median(window)))
scale = 1e-6 if local_mad == 0 else local_mad
if np.abs(data[i] - rolling_med[i]) / scale > threshold:
flags[i] = True
return flags
series = np.array([20.2, 20.5, 20.1, 20.4, 28.6, 20.3, 20.6, 20.2, 20.5, 20.4])
outliers = hampel_filter(series, k=2, threshold=3.0)
print("Outlier indices:", np.where(outliers)[0])
R Implementation (tsoutliers)
In R, the tsoutliers package provides automated detection and classification of AO, LS, and TC structures, as detailed in comprehensive time series analysis in R workflows:
if (!requireNamespace("tsoutliers", quietly = TRUE)) install.packages("tsoutliers")
library(tsoutliers)
y <- ts(c(20.2, 20.5, 20.1, 20.4, 28.6, 20.3, 20.6, 20.2, 20.5, 20.4), frequency = 1)
outlier_model <- tso(y, types = c("AO", "LS", "TC"), cval = 3.0)
print(outlier_model$outliers)
Microsoft Excel Implementation
In Excel, local window filtering is configured for data in cells B2:B11 (evaluating row 4 with k = 2 span B2:B6):
- Local Median (Cell C4):
=MEDIAN(B2:B6) - Absolute Deviation (Cell D4):
=ABS(B4-C4) - Raw MAD (Cell E4):
=MEDIAN(ABS(B2:B6-C4)) - Scaled Dispersion (Cell F4):
=1.4826*E4 - Outlier Decision Flag (Cell G4):
=IF(D4 > 3*F4, "OUTLIER", "NORMAL")
Frequently asked questions
What is an outlier in time series data?
An outlier in time series data is an observation, abrupt level shift, or sequence pattern that departs significantly from the underlying trend, seasonal cycle, or autoregressive structure of sequential measurements. Unlike cross-sectional outliers, time series outliers are defined relative to their temporal context rather than the global distribution alone.
What are the different types of time series outliers?
The four primary typologies standardized in statistical literature are Additive Outliers (AO, single-period shocks), Level Shifts (LS, permanent step changes in baseline mean), Temporary Changes (TC, initial shocks that decay exponentially over time), and Innovational Outliers (IO, shocks entering the internal white-noise process that propagate via model dynamics).
How do you detect outliers in time series data?
Outliers are detected using three primary approaches: robust nonparametric local window filtering (such as the Hampel filter using rolling median and MAD), seasonal-trend decomposition (such as robust STL to screen remainder residuals), and parametric time series modeling (such as analyzing standardized one-step-ahead prediction errors in ARIMA frameworks).
Why do standard outlier detection methods fail on time series?
Standard methods like global Z-scores or basic Isolation Forests assume observations are independent and identically distributed. They fail on time series because they cannot account for serial autocorrelation, trend growth, or cyclical seasonality, leading to severe false alarms during expected peaks and failing to identify contextual anomalies.
What is the difference between anomaly detection in real-time vs batch processing?
Batch detection operates on complete historical datasets using symmetric two-sided windows and smoothing passes that incorporate both past and future observations. Real-time streaming detection relies strictly on causal one-sided windows looking backward, requiring multi-step lag confirmation to differentiate isolated spikes from sustained structural level shifts.
How do you handle zero-inflated or intermittent time series?
In intermittent demand or zero-inflated time series (such as spare-parts consumption or rare error logs), traditional variance-based fences break down because medians and quartiles are frequently zero. These series require specialized hurdle models, Croston’s method, or discrete compound Poisson distributions rather than continuous Gaussian estimators.
The data table below compares the statistical mechanics, breakdown points, computational complexities, and software packages across five standard time series outlier detection frameworks.
Sources
- National Institute of Standards and Technology: 1.3.5.17. Detection of Outliers, checked 2026-11-24
- U.S. Census Bureau: X-13ARIMA-SEATS Seasonal Adjustment Program, checked 2026-11-24
- Eurostat: ESS guidelines on seasonal adjustment – Products Manuals and Guidelines – Eurostat, checked 2026-11-24
- The Comprehensive R Archive Network: CRAN: Package tsoutliers, checked 2026-11-24
- Statsmodels Development Team: statsmodels.tsa.seasonal.STL — statsmodels 0.15.0, checked 2026-11-24
- SciPy Community: medfilt — SciPy v1.18.0 Manual, checked 2026-11-24
Data: Comparison of Time Series Outlier Detection Frameworks and Methods
Cross-method comparison of five standard time series outlier detection approaches across algorithmic family, breakdown point, structural anomaly capability, temporal dependency handling, and primary reference implementation. Compiled from NIST/SEMATECH guidelines, U.S. Census Bureau X-13ARIMA-SEATS documentation, Eurostat seasonal adjustment standards, and official software documentation.
| Method | Algorithmic Family | Breakdown Point (percent) | Detectable Outlier Typologies | Computational Complexity | Standard Software Implementation |
|---|---|---|---|---|---|
| Hampel Identifier (Rolling MAD) | Robust Local Filtering | 50 | Additive Outliers (isolated point spikes) | O(k log k) per window | SciPy signal.medfilt / R pracma |
| STL Remainder Screening | Nonparametric Decomposition | 50 | Additive Outliers and seasonal transients | O(N) per Loess iteration | statsmodels.tsa.seasonal.STL / R stats::stl |
| X-13ARIMA-SEATS Regressors | Parametric Dynamic Modeling | 0 | Additive Outlier, Level Shift, Temporary Change, Innovational Outlier | O(N) per ARIMA iteration | US Census Bureau X-13AS / R tsoutliers |
| Linear Forecasting Residuals (ARIMA) | Parametric Time Series | 0 | Additive Outliers and Innovational Outliers | O(N) fitting | statsmodels.tsa.arima.ARIMA / R forecast::auto.arima |
| Local Outlier Factor on Delay Embeddings | Unsupervised Density Estimation | 50 | Contextual Subsequence Anomalies | O(N log N) with kd-tree | scikit-learn.neighbors.LocalOutlierFactor |
Sources
- 1.3.5.17. Detection of Outliers (accessed 2026-11-24)
- X-13ARIMA-SEATS Seasonal Adjustment Program (accessed 2026-11-24)
- ESS guidelines on seasonal adjustment - Products Manuals and Guidelines - Eurostat (accessed 2026-11-24)
- CRAN: Package tsoutliers (accessed 2026-11-24)
- statsmodels.tsa.seasonal.STL — statsmodels 0.15.0 (accessed 2026-11-24)
- medfilt — SciPy v1.18.0 Manual (accessed 2026-11-24)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







