STL decomposition

Also known as: Seasonal-Trend decomposition using Loess

On this page 7

STL decomposition, short for Seasonal-Trend decomposition using Loess, is a filtering procedure that splits a time series into three additive parts: a trend component, a seasonal component and a remainder. In time series & forecasting it is one of the most widely used tools for understanding structure in data before a model is fitted, because it handles any regular seasonal period and can be made robust to outliers.

The method was published in 1990 by Cleveland, Cleveland, McRae and Terpenning. Its core idea is to estimate each component with locally weighted regression (loess) and to refine the estimates through nested iterations, so that the trend does not absorb seasonality and the seasonal pattern does not absorb the trend.

How STL separates trend, season and remainder

STL assumes the additive model Y = T + S + R, where each observation equals trend plus seasonal plus remainder. The algorithm runs an inner loop that alternates between estimating the seasonal and trend components, wrapped in an optional outer loop that computes robustness weights.

  1. Detrend the series by subtracting the current trend estimate, which starts at zero.
  2. Smooth each cycle-subseries with loess; for monthly data, all Januaries form one subseries, all Februaries another.
  3. Low-pass filter the result with moving averages and loess, then subtract it so the seasonal part carries no trend.
  4. Deseasonalize the original series by subtracting the new seasonal estimate.
  5. Smooth the deseasonalized series with loess to obtain the updated trend.

In the outer loop, the remainder R = Y – T – S is used to compute bisquare robustness weights. Observations with large residuals, measured against roughly six times the median absolute residual, receive weights near zero, so isolated spikes stop distorting the trend and seasonal estimates in the next pass.

Key STL parameters and their effects

STL behavior is controlled by a handful of smoothing spans and iteration counts. Most implementations derive sensible defaults from the period, but the seasonal and trend windows deserve deliberate choice because they decide how much change each component may show.

ParameterMeaningTypical settingEffect of a larger value
Period (n_p)Observations per seasonal cycle12 monthly, 7 daily, 24 hourlyDefines the pattern being extracted
Seasonal window (n_s)Loess span across cycle-subseriesOdd, at least 7Seasonal shape changes more slowly
Trend window (n_t)Loess span for the trendAbout 1.5 times the period or moreSmoother, less reactive trend
Low-pass window (n_l)Span of the low-pass filterSmallest odd value above the periodRarely changed in practice
Inner iterations (n_i)Passes of the inner loop2 without robustness, 1 with itLittle gain beyond defaults
Outer iterations (n_o)Robustness passes0, or about 5-15 when robustStronger outlier downweighting
Main STL parameters

Setting the seasonal window to periodic forces an identical seasonal pattern in every cycle, which reproduces classical decomposition behavior. A small seasonal window lets the pattern evolve year by year, which suits retail data whose holiday peak shifts in size over time but risks leaking noise into the seasonal component.

STL compared with other decomposition methods

STL is one of several ways to separate seasonality from trend, and the choice depends on data frequency, required statistical rigor and calendar effects. The table contrasts it with the most common alternatives.

MethodSeasonal patternStrengthsWeaknesses
Classical decompositionFixed every cycleSimple moving averagesNo trend at series ends, outlier-sensitive
X-13ARIMA-SEATSCan evolveOfficial statistics, trading-day effectsMonthly and quarterly data only
STLCan evolve, user-controlledAny period, robust optionAdditive only, no calendar adjustment
MSTLSeveral periods at onceHourly and daily data with multiple cyclesMore parameters to tune
Prophet componentsFourier-based, smoothHolidays and changepoints built inModel-based, less local flexibility
Decomposition methods side by side

Unlike X-13ARIMA-SEATS, STL does not adjust for trading days or moving holidays such as Easter. Unlike classical decomposition, it produces trend values at both ends of the series. Its extension MSTL applies STL repeatedly to remove several seasonal periods, for example daily and weekly cycles in electricity load.

Using STL in forecasting and machine learning

STL is a preprocessing and diagnostic step, not a forecasting model by itself. A common pattern is decompose, forecast, recombine: the seasonally adjusted series (trend plus remainder) is forecast with ETS, ARIMA or a neural model, and the seasonal component is projected forward with a seasonal naive rule and added back.

UseWhat STL providesDownstream step
ForecastingSeasonally adjusted seriesFit ETS or ARIMA, then reseasonalize
Anomaly detectionRemainder componentFlag points beyond a robust threshold
Feature engineeringTrend and seasonal strengthInputs to global or ensemble models
Exploratory analysisVisual component plotsJudge stability of seasonality
Typical STL applications

The strength of seasonality can be measured as one minus the ratio of remainder variance to the variance of seasonal plus remainder; values near 1 indicate strong seasonality. Such statistics are widely used as features when a single global model is trained across thousands of series.

Limitations and common mistakes with STL

The most frequent error is applying additive STL to data with multiplicative seasonality, where seasonal swings grow with the level. The standard remedy is a logarithmic or Box-Cox transformation before decomposition, followed by back-transformation of the components.

  • Too short a series: at least two full cycles are required, and reliable seasonal estimates usually need many more.
  • Wrong period: an incorrect period produces a meaningless seasonal component and a remainder full of structure.
  • Overly flexible windows: a small trend window lets the trend chase noise and short shocks.
  • Look-ahead leakage: decomposing the full history before a train-test split lets loess use future values, which inflates backtest accuracy.
  • End effects: estimates near the most recent observations are less stable and may revise as new data arrive.

STL also assumes regularly spaced observations and offers no uncertainty intervals for its components. For forecasting with prediction intervals, the decomposition must be combined with a probabilistic model of the adjusted series.

Stripped to the essentials

Many numbers that change over time mix three things. There is a slow long-term direction. There is a pattern that repeats, such as every year or every week. And there is leftover noise.

STL pulls these three apart. It works like sorting a pile of mail into bills, letters and advertising. Each part can then be studied on its own. This makes it much easier to see what is really changing and what is just the usual seasonal rhythm.

Where it is applied

A regional water utility records daily water consumption over six years and wants to plan pumping capacity. Demand rises every summer and dips on weekends, while population growth adds a slow upward drift. Analysts first apply MSTL with periods of 7 and 365 days and enable robust iterations, because a pipe burst produced several days of extreme readings.

The decomposition shows a steady trend increase of about 2% per year, a summer peak roughly 35% above the winter level and a weekend dip of about 8%. The robust weights isolate the burst in the remainder instead of distorting the summer pattern. The team then forecasts the adjusted series with an ETS model and adds the projected seasonal components back, producing a next-summer peak estimate that guides the decision to commission an additional pump before the hot season.