Trend–Seasonal Decomposition and Rolling Statistics for Time Series
Separating the long-run direction and the seasonal effect within a month-to-month difference.
Suppose we are looking at the monthly number of trips on a city bike-share service. Usage tends to rise in summer and fall in winter, but the service itself may also become more popular year after year.
That is why, just because this July's trip count is higher than last December's, we cannot say the business grew rapidly. The two months fall in different seasons, and they come at different points in the service's operation.
Data recorded in time order like this are called a time series. To understand a time series, you need to separate the trend, which shows the long-run direction; seasonality, which repeats over a fixed cycle; and the remainder that neither of these explains.
On top of that, using rolling statistics such as the moving average and the rolling standard deviation lets you check how persistent and how unstable changes over a given period are. In this article, we use monthly bike-share data to calculate moving averages, additive and multiplicative decomposition, STL, seasonal adjustment, and rolling volatility, and look at how to interpret the results.
What is different about time series data?
Ordinary cross-sectional data compare the values of many subjects, while time series data look at how the same subject changes over time.
So the order and spacing of observations matter. If you shuffle the order of the monthly trip counts, it becomes hard to see the pattern of rising in spring and falling in winter.
A time series can show a level, a trend, seasonality, and irregular variation all at once. For example, a bike-share service's average usage might be about 100,000 trips a month, but it grows over the long run, with July–August above average and January–February below. Fluctuations caused by weather or a temporary service outage should be treated separately from these repeating patterns.
Decomposition is first and foremost a tool for understanding the data. The decomposition itself does not guarantee future trip counts or prove the causes of changes in usage.
Real example: monthly trips on a city bike-share service
Suppose a city tallied bike-share trips for 48 months, from January 2022 to December 2025.
The figures are in thousands of trips.
| Item | Setting |
|---|---|
| Subject observed | Citywide bike-share service |
| Period | Jan 2022 – Dec 2025 |
| Frequency | Monthly, 48 observations |
| Outcome variable | Monthly rentals (thousands) |
| Seasonal period | 12 months |
| Questions of interest | Is usage increasing over the long run? How large is the seasonal effect that repeats every year? |
The values below are some of the observations, to help understand the example.
| Time | Rentals (thousands) |
|---|---|
| Jan 2024 | 66 |
| Feb 2024 | 71 |
| Mar 2024 | 92 |
| Apr 2024 | 110 |
| May 2024 | 123 |
| Jun 2024 | 132 |
| Jul 2024 | 140 |
| Aug 2024 | 138 |
| Sep 2024 | 126 |
| Oct 2024 | 115 |
| Nov 2024 | 91 |
| Dec 2024 | 76 |
| 2024 total | 1,280 |
Looking at just these 12 months, you can see a pattern within the year: high in summer and low in winter. But to judge the long-run trend, you need to compare the full 2022–2025 data. Seasonality is not established from a single year's changes; you need to examine whether it repeats across several years.
How do you identify the trend?
The trend is the direction that persists over a long period once short-term ups and downs are set aside.
For example, suppose the bike-share service's annual trips increased from 960 thousand in 2022 to 1,080 thousand in 2023, 1,280 thousand in 2024, and 1,400 thousand in 2025. These values are evidence that usage has grown over the long run.
| Year | Annual trips (thousands) | Year-over-year growth |
|---|---|---|
| 2022 | 960 | — |
| 2023 | 1,080 | 12.5% |
| 2024 | 1,280 | 18.5% |
| 2025 | 1,400 | 9.4% |
Year-over-year growth is calculated as (this year − previous year) ÷ previous year × 100. The growth rate for 2024 is (1,280 − 1,080) ÷ 1,080 × 100 ≈ 18.5%.
However, using annual totals like this can hide monthly fluctuations. In a real analysis, it is good to plot the raw series together with a smoothly estimated trend line, and to check for level shifts or sudden structural changes.
What is a moving average?
A moving average is calculated by averaging the observations in a fixed window and then shifting that window forward one time point at a time.
It is used to smooth out short-term fluctuations so that the course of the series is easier to see. For example, trips in April–June 2024 were 110, 123, and 132 thousand, so the 3-month moving average for this window is (110 + 123 + 132) ÷ 3 ≈ 121.7 thousand.
| Reference month | Months included | 3-month trailing moving average (thousands) |
|---|---|---|
| May 2024 | Mar–May | 108.3 |
| Jun 2024 | Apr–Jun | 121.7 |
| Jul 2024 | May–Jul | 131.7 |
| Aug 2024 | Jun–Aug | 136.7 |
The moving averages in this table are trailing moving averages that use the current month and the two months before it. So the July value is calculated from May–July only and uses no future values. A centered moving average, by contrast, uses observations before and after a given month, so carelessly using it as an input for real-time forecasting can cause future information leakage.
How do 3-month and 12-month moving averages differ?
The window length of a moving average determines which fluctuations are kept and which are smoothed out.
A 3-month moving average reflects recent changes relatively quickly, but much of the seasonal up-and-down can remain. For monthly data, a 12-month moving average, on the other hand, is useful for smoothing out the annual seasonal cycle but can be slow to show a change in the trend's direction.
| Window | Advantages | Cautions |
|---|---|---|
| 3-month | Responds quickly to recent changes | Seasonal fluctuations may remain |
| 6-month | Smooths short-term fluctuations more | Somewhat slow to detect turning points |
| 12 months | Useful for smoothing the annual seasonal cycle | More points at both ends cannot be calculated, and it responds slowly to change |
Since 12 months is an even-length window, traditional classical decomposition can use a centered trend obtained through two stages of moving averages. But the 12-month moving average itself is not always an accurate seasonally adjusted value. When observations are irregularly spaced or the seasonal pattern changes, a different approach is needed.
How does time series decomposition work?
Time series decomposition splits observations into trend, seasonality, and remainder.
The typical structures are additive decomposition and multiplicative decomposition.
Additive: Yt = Tt + St + Rt
Multiplicative: Yt = Tt × St × Rt
An additive model can be suitable when the absolute size of the seasonal swings is similar regardless of the level. For example, if summer usage is roughly 20,000 trips higher every year, an additive structure is intuitive. On the other hand, if the gap between summer and winter grows in proportion as usage grows, you can consider a multiplicative structure.
Multiplicative decomposition is generally used with positive data. When a log transformation is possible, you can also take logs to handle a multiplicative relationship in additive form. But if the data include zeros, be especially careful with how logs and transformations are handled.
What is STL decomposition, and why use it?
STL (Seasonal and Trend decomposition using Loess) estimates trend and seasonality using local regression (LOESS).
Its advantage over classical decomposition is that it can flexibly handle situations where the seasonal pattern changes gradually.
STL provides an additive decomposition by default. So if the seasonal swings grow in proportion to usage, you can consider an appropriate transformation, such as a log transformation.
The main settings include the seasonal period, the smoothness of the seasonal component, the smoothness of the trend component, and a robust decomposition option that reduces the influence of outliers. When analyzing an annually repeating pattern in monthly data, it is natural to set the period to 12.
However, 48 months of data contain only four annual cycles, which limits how precisely you can judge the stability of the seasonal pattern and the long-run trend. STL results should be treated as estimates that describe the data rather than as established facts.
How do you read the numbers in a decomposition table?
Suppose trips in July 2024 were 140 thousand, and the STL estimates for that month were as follows.
| Component | July 2024 value (thousands) | Interpretation |
|---|---|---|
| Trend (T) | 108 | Baseline usage expected over the long run |
| Seasonal (S) | +26 | The recurring seasonal effect of July |
| Remainder (R) | +6 | Difference not explained by trend and seasonality |
| Actual trips (Y) | 140 | 108 + 26 + 6 |
Since an additive decomposition is used here, 140 = 108 + 26 + 6. A seasonal component of +26 thousand for July means the model estimated a pattern in which that month's trips run about 26 thousand above the trend level for seasonal reasons.
The remainder of +6 thousand is the difference that trend and seasonality could not explain. However, it cannot be immediately interpreted as the effect of a specific event, because many factors, such as weather conditions, events, service outages, and data errors, can affect the remainder.
How is seasonal adjustment done?
Seasonal adjustment removes recurring seasonal effects so that changes between time points are easier to compare.
In an additive decomposition, you subtract the estimated seasonal component from the actual observation.
YtSA = Yt − St = Tt + Rt
In the July 2024 example above, actual trips were 140 thousand and the seasonal component was +26 thousand, so seasonally adjusted trips are 140 − 26 = 114 thousand.
This figure shows "the level with July's seasonal boost removed." It does not mean only 114 thousand trips were actually taken. Also, seasonally adjusted values can still include temporary shocks and estimation error, so they should not be confused with the trend component.
What does the rolling standard deviation show?
Besides the moving average, rolling statistics also include the rolling standard deviation.
The rolling standard deviation shows how much the observations have fluctuated over a recent fixed period. For example, if trips over the last 3 months were 110, 123, and 132 thousand, the sample standard deviation is about 11.1 thousand. Unlike the mean, this figure summarizes the size of the fluctuations in that window.
However, in strongly seasonal data such as bike usage, a high rolling standard deviation of the raw observations does not necessarily mean the service has become more unstable. Volatility may look large simply because of seasonal rises and falls.
If the goal is to spot abnormal fluctuations, it may be more appropriate to look at the rolling standard deviation of the remainder after removing trend and seasonality. Even then, you should also examine the window length and the influence of outliers.
Which graphs and diagnostics should you look at together?
The structure of a time series decomposition often shows up better in graphs than in tables.
A decomposition plot that stacks the raw series, trend, seasonality, and remainder from top to bottom lets you compare the size of each component and how it changes over time.
| Visualization / diagnostic | Question to check |
|---|---|
| Raw series | Is there a long-run rise or decline, or any odd spikes or drops? |
| Trend plot | Has the direction or slope of the trend changed? |
| Seasonal component | Is there a pattern that repeats at similar times? |
| Remainder plot | Do unexplained outliers or structure remain? |
| ACF (remainder autocorrelation) | Does temporal dependence remain after decomposition? |
| Rolling standard deviation | Does the level of volatility change over time? |
If a clear seasonal pattern or autocorrelation persists in the remainder, the chosen decomposition method may not have adequately explained the structure of the data. However, a descriptive decomposition can be useful even if the remainder is not perfect white noise. How important remainder diagnostics are depends on the purpose of the analysis.
Points to watch in the analysis
Distinguish the observation frequency from the seasonal period.
A 12-month cycle in monthly data differs from a roughly 52-week cycle in weekly data, and daily data can have multiple patterns, such as day-of-week and annual seasonality. Basic STL, which handles only one seasonal period at a time, cannot explain every kind of complex seasonality.
Check how the moving average is aligned in time.
A centered moving average can use past and future observations together, so in real-time forecasting or policy evaluation, take care that future information does not get mixed in.
Do not interpret trend and seasonality as causes.
High summer usage does not let you conclude that temperature alone is the cause, and a rising trend does not let you conclude that marketing was effective. Causal relationships require a separate study design.
With short data, decomposition results can be unstable.
In 48 months of data, the annual seasonal cycle repeats only four times. To judge in detail whether seasonality has changed, a longer observation period helps.
Distinguish forecasting from descriptive decomposition.
Decomposition is useful for understanding a time series, but by itself it does not prove the performance of a forecasting model. If forecasting is the goal, you need separate time series validation and an evaluation of forecast error.
How do you report the results?
When reporting a trend and seasonality analysis, it is good to state clearly the subject and period observed, the observation frequency, the seasonal period, the decomposition method, the window lengths of the rolling statistics, and the key figures.
If there were log transformations, outlier treatment, or adjustments for missing values, you should also describe those steps.
Example report
To analyze the monthly usage pattern of a city bike-share service, trip counts for the 48 months from January 2022 to December 2025 were examined. Annual trips increased from 960 thousand in 2022 to 1,400 thousand in 2025, confirming long-run growth in usage. To examine the annually repeating pattern in the monthly data, an additive STL decomposition with a 12-month seasonal period was applied.
Actual trips in July 2024 were 140 thousand, with an estimated trend component of 108 thousand, a seasonal component of +26 thousand, and a remainder of +6 thousand. The resulting seasonally adjusted trips for July were 114 thousand. These results show that the summer increase in usage is related to a recurring seasonal pattern and needs to be interpreted separately from the long-run upward trend in usage.
In real studies, it is good to present the full time series, the decomposition plots, and the remainder diagnostics together.
Change becomes visible only once you separate trend from seasonality
The mere fact that one point in a time series is high or low makes it hard to judge whether a long-run change has occurred.
This is because observations mix trend, seasonality, and temporary fluctuation together.
Moving averages smooth out short-term wobbles to show the overall course, and decomposition methods such as STL help you interpret observations by splitting them into trend, seasonality, and remainder. Seasonal adjustment makes values from different months easier to compare, and the rolling standard deviation summarizes the level of fluctuation over a given period.
However, decomposition describes the patterns that appear in the data; it does not prove the causes of change or accurately predict the future. It is important to choose the period, cycle, and decomposition method that fit the purpose of the analysis and to check the results together with the raw data.
The key is not to take month-to-month differences at face value, but to read them by separating the long-run direction from the recurring seasonal effect.