Skip to main content

6  Time series decomposition

Time series data can exhibit a variety of patterns, and it is often helpful to split a time series into several components, each representing an underlying pattern category.

In Section 2.3 we discussed three types of time series patterns: trend, seasonality and cycles. When we decompose a time series into components, we usually combine the trend and cycle into a single trend-cycle component (sometimes called the trend for simplicity). Thus we think of a time series as comprising three components: a trend-cycle component, a seasonal component, and a remainder component (containing anything else in the time series).

In this chapter, we consider some common methods for extracting these components from a time series. Often this is done to help improve understanding of the time series, but it can also be used to improve forecast accuracy.

6.1 Time series components

If we assume an additive decomposition, then we can write y_{t} = S_{t} + T_{t} + R_t, where y_{t} is the data, S_{t} is the seasonal component, T_{t} is the trend-cycle component, and R_t is the remainder component, all at period t. Alternatively, a multiplicative decomposition would be written as y_{t} = S_{t} \times T_{t} \times R_t.

The additive decomposition is the most appropriate if the magnitude of the seasonal fluctuations, or the variation around the trend-cycle, does not vary with the level of the time series. When the variation in the seasonal pattern, or the variation around the trend-cycle, appears to be proportional to the level of the time series, then a multiplicative decomposition is more appropriate. Multiplicative decompositions are common with economic time series.

An alternative to using a multiplicative decomposition is to first transform the data until the variation in the series appears to be stable over time, then use an additive decomposition. When a log transformation has been used, this is equivalent to using a multiplicative decomposition because y_{t} = S_{t} \times T_{t} \times R_t \quad\text{is equivalent to}\quad \log y_{t} = \log S_{t} + \log T_{t} + \log R_t.

Electrical equipment manufacturing

We will look at several methods for obtaining the components S_{t}, T_{t} and R_{t} later in this chapter, but first, it is helpful to see an example. We will decompose the new orders index for electrical equipment shown in Figure 6.1. The data show the number of new orders for electrical equipment (computer, electronic and optical products) in the Euro area (16 countries). The data have been adjusted by working days and normalised so that a value of 100 corresponds to 2005.

Figure 6.1: Electrical equipment orders: the trend-cycle component (red) and the raw data (grey).

Figure 6.1 shows the trend-cycle component, T_t, in red and the original data, y_t, in grey. The trend-cycle shows the overall movement in the series, ignoring the seasonality and any small random fluctuations.

Figure 6.2 shows an additive decomposition of these data. The method used for estimating components in this example is STL, which is discussed in Section 6.6.

Figure 6.2: The electrical equipment orders (top) and its three additive components.

The three components are shown separately in the bottom three panels of Figure 6.2. These components can be added together to reconstruct the data shown in the top panel. Notice that the seasonal component changes slowly over time, so that any two consecutive years have similar patterns, but years far apart may have different seasonal patterns. The remainder component shown in the bottom panel is what is left over when the seasonal and trend-cycle components have been subtracted from the data.

The grey bars to the right of each panel show the relative scales of the components. Each grey bar represents the same length but because the plots are on different scales, the bars vary in size. The large grey bar in the bottom panel shows that the variation in the remainder component is small compared to the variation in the data, which has a bar about one quarter the size. If we shrunk the bottom three panels until their bars became the same size as that in the data panel, then all the panels would be on the same scale.

Seasonally adjusted data

If the seasonal component is removed from the original data, the resulting values are the “seasonally adjusted” data. For an additive decomposition, the seasonally adjusted data are given by y_{t} - S_{t}, and for multiplicative data, the seasonally adjusted values are obtained using y_{t}/S_{t}.

Figure 6.3 shows the seasonally adjusted electrical equipment orders.

Figure 6.3: Seasonally adjusted electrical equipment orders (blue) and the original data (grey).

If the variation due to seasonality is not of primary interest, the seasonally adjusted series can be useful. For example, monthly unemployment data are usually seasonally adjusted in order to highlight variation due to the underlying state of the economy rather than the seasonal variation. An increase in unemployment due to school leavers seeking work is seasonal variation, while an increase in unemployment due to an economic recession is non-seasonal. Most economic analysts who study unemployment data are more interested in the non-seasonal variation. Consequently, employment data (and many other economic series) are usually seasonally adjusted.

Seasonally adjusted series contain the remainder component as well as the trend-cycle. Therefore, they are not “smooth”, and “downturns” or “upturns” can be misleading. If the purpose is to look for turning points in a series, and interpret any changes in direction, then it is better to use the trend-cycle component rather than the seasonally adjusted data.

6.2 Moving averages

The classical method of time series decomposition originated in the 1920s and was widely used until the 1950s. It still forms the basis of many time series decomposition methods, so it is important to understand how it works. The first step in a classical decomposition is to use a moving average method to estimate the trend-cycle, so we begin by discussing moving averages.

Moving average smoothing

A moving average of order m can be written as \hat{T}_{t} = \frac{1}{m} \sum_{j=-k}^k y_{t+j}, \tag{6.1} where m = 2k + 1. That is, the estimate of the trend-cycle at time t is obtained by averaging values of the time series within k periods of t. Observations that are nearby in time are also likely to be close in value. Therefore, the average eliminates some of the randomness in the data, leaving a smooth trend-cycle component. We call this an m-MA, meaning a moving average of order m.

autoplot(elecsales) +
  xlab("Year") +
  ylab("GWh") +
  ggtitle("Annual electricity sales: South Australia")
Figure 6.4: Residential electricity sales (excluding hot water) for South Australia: 1989–2008.

For example, consider Figure 6.4 which shows the volume of electricity sold to residential customers in South Australia each year from 1989 to 2008 (hot water sales have been excluded). The data are also shown in Table 6.1.

Table 6.1: Annual electricity sales to residential customers in South Australia. 1989–2008.
Year Sales (GWh) 5-MA
1989 2354.34
1990 2379.71
1991 2318.52 2381.53
1992 2468.99 2424.56
1993 2386.09 2463.76
1994 2569.47 2552.60
1995 2575.72 2627.70
1996 2762.72 2750.62
1997 2844.50 2858.35
1998 3000.70 3014.70
1999 3108.10 3077.30
2000 3357.50 3144.52
2001 3075.70 3188.70
2002 3180.60 3202.32
2003 3221.60 3216.94
2004 3176.20 3307.30
2005 3430.60 3398.75
2006 3527.48 3485.43
2007 3637.89
2008 3655.00

In the last column of this table, a moving average of order 5 is shown, providing an estimate of the trend-cycle. The first value in this column is the average of the first five observations (1989–1993); the second value in the 5-MA column is the average of the values for 1990–1994; and so on. Each value in the 5-MA column is the average of the observations in the five year window centred on the corresponding year. In the notation of Equation 6.1, column 5-MA contains the values of \hat{T}_{t} with k = 2 and m = 2k + 1 = 5. This is easily computed using

ma(elecsales, 5)

There are no values for either the first two years or the last two years, because we do not have two observations on either side. Later we will use more sophisticated methods of trend-cycle estimation which do allow estimates near the endpoints.

To see what the trend-cycle estimate looks like, we plot it along with the original data in Figure 6.5.

autoplot(elecsales, series = "Data") +
  autolayer(ma(elecsales, 5), series = "5-MA") +
  xlab("Year") +
  ylab("GWh") +
  ggtitle("Annual electricity sales: South Australia") +
  scale_colour_manual(
    values = c("Data" = "grey50", "5-MA" = "red"),
    breaks = c("Data", "5-MA")
  )
Figure 6.5: Residential electricity sales (black) along with the 5-MA estimate of the trend-cycle (red).

Notice that the trend-cycle (in red) is smoother than the original data and captures the main movement of the time series without all of the minor fluctuations. The order of the moving average determines the smoothness of the trend-cycle estimate. In general, a larger order means a smoother curve. Figure 6.6 shows the effect of changing the order of the moving average for the residential electricity sales data.

Figure 6.6: Different moving averages applied to the residential electricity sales data.

Simple moving averages such as these are usually of an odd order (e.g., 3, 5, 7, etc.). This is so they are symmetric: in a moving average of order m = 2k + 1, the middle observation, and k observations on either side, are averaged. But if m was even, it would no longer be symmetric.

Moving averages of moving averages

It is possible to apply a moving average to a moving average. One reason for doing this is to make an even-order moving average symmetric.

For example, we might take a moving average of order 4, and then apply another moving average of order 2 to the results. In the following table, this has been done for the first few years of the Australian quarterly beer production data.

beer2 <- window(ausbeer, start = 1992)
ma4 <- ma(beer2, order = 4, centre = FALSE)
ma2x4 <- ma(beer2, order = 4, centre = TRUE)
A moving average of order 4 applied to the quarterly beer data, followed by a moving average of order 2.
Year Quarter Observation 4-MA 2x4-MA
1992 Q1 443
1992 Q2 410 451.25
1992 Q3 420 448.75 450.00
1992 Q4 532 451.50 450.12
1993 Q1 433 449.00 450.25
1993 Q2 421 444.00 446.50
1993 Q3 410 448.00 446.00
1993 Q4 512 438.00 443.00
1994 Q1 449 441.25 439.62
1994 Q2 381 446.00 443.62
1994 Q3 423 440.25 443.12
1994 Q4 531 447.00 443.62
1995 Q1 426 445.25 446.12
1995 Q2 408 442.50 443.88
1995 Q3 416 438.25 440.38
1995 Q4 520 435.75 437.00
1996 Q1 409 431.25 433.50
1996 Q2 398 428.00 429.62
1996 Q3 398 433.75 430.88
1996 Q4 507 433.75 433.75

The notation “2 \times 4-MA” in the last column means a 4-MA followed by a 2-MA. The values in the last column are obtained by taking a moving average of order 2 of the values in the previous column. For example, the first two values in the 4-MA column are 451.25=(443+410+420+532)/4 and 448.75=(410+420+532+433)/4. The first value in the 2x4-MA column is the average of these two: 450.00=(451.25+448.75)/2.

When a 2-MA follows a moving average of an even order (such as 4), it is called a “centred moving average of order 4”. This is because the results are now symmetric. To see that this is the case, we can write the 2 \times 4-MA as follows: \begin{align*} \hat{T}_{t} & = \frac{1}{2}\Big[ \frac{1}{4} (y_{t-2} + y_{t-1} + y_{t} + y_{t+1}) + \frac{1}{4} (y_{t-1} + y_{t} + y_{t+1} + y_{t+2})\Big] \\ & = \frac{1}{8}y_{t-2} + \frac14y_{t-1} + \frac14y_{t} + \frac14y_{t+1} + \frac18y_{t+2}. \end{align*} It is now a weighted average of observations that is symmetric. By default, the ma() function in R will return a centred moving average for even orders (unless center=FALSE is specified).

Other combinations of moving averages are also possible. For example, a 3 \times 3-MA is often used, and consists of a moving average of order 3 followed by another moving average of order 3. In general, an even order MA should be followed by an even order MA to make it symmetric. Similarly, an odd order MA should be followed by an odd order MA.

Estimating the trend-cycle with seasonal data

The most common use of centred moving averages is for estimating the trend-cycle from seasonal data. Consider the 2 \times 4-MA: \hat{T}_{t} = \frac{1}{8}y_{t-2} + \frac14y_{t-1} + \frac14y_{t} + \frac14y_{t+1} + \frac18y_{t+2}. When applied to quarterly data, each quarter of the year is given equal weight as the first and last terms apply to the same quarter in consecutive years. Consequently, the seasonal variation will be averaged out and the resulting values of \hat{T}_t will have little or no seasonal variation remaining. A similar effect would be obtained using a 2 \times 8-MA or a 2 \times 12-MA to quarterly data.

In general, a 2 \times m-MA is equivalent to a weighted moving average of order m + 1 where all observations take the weight 1/m, except for the first and last terms which take weights 1/(2m). So, if the seasonal period is even and of order m, we use a 2 \times m-MA to estimate the trend-cycle. If the seasonal period is odd and of order m, we use a m-MA to estimate the trend-cycle. For example, a 2 \times 12-MA can be used to estimate the trend-cycle of monthly data and a 7-MA can be used to estimate the trend-cycle of daily data with a weekly seasonality.

Other choices for the order of the MA will usually result in trend-cycle estimates being contaminated by the seasonality in the data.

Example: Electrical equipment manufacturing

autoplot(elecequip, series = "Data") +
  autolayer(ma(elecequip, 12), series = "12-MA") +
  xlab("Year") +
  ylab("New orders index") +
  ggtitle("Electrical equipment manufacturing (Euro area)") +
  scale_colour_manual(
    values = c("Data" = "grey", "12-MA" = "red"),
    breaks = c("Data", "12-MA")
  )
Figure 6.7: A 2x12-MA applied to the electrical equipment orders index.

Figure 6.7 shows a 2 \times 12-MA applied to the electrical equipment orders index. Notice that the smooth line shows no seasonality; it is almost the same as the trend-cycle shown in Figure 6.1, which was estimated using a much more sophisticated method than a moving average. Any other choice for the order of the moving average (except for 24, 36, etc.) would have resulted in a smooth line that showed some seasonal fluctuations.

Weighted moving averages

Combinations of moving averages result in weighted moving averages. For example, the 2 \times 4-MA discussed above is equivalent to a weighted 5-MA with weights given by \left[ \frac{1}{8},\frac{1}{4},\frac{1}{4},\frac{1}{4},\frac{1}{8} \right]. In general, a weighted m-MA can be written as \hat{T}_t = \sum_{j=-k}^k a_j y_{t+j}, where k = (m - 1)/2, and the weights are given by \left[ a_{-k},\dots,a_k \right]. It is important that the weights all sum to one and that they are symmetric so that a_j = a_{-j}. The simple m-MA is a special case where all of the weights are equal to 1/m.

A major advantage of weighted moving averages is that they yield a smoother estimate of the trend-cycle. Instead of observations entering and leaving the calculation at full weight, their weights slowly increase and then slowly decrease, resulting in a smoother curve.

6.3 Classical decomposition

The classical decomposition method originated in the 1920s. It is a relatively simple procedure, and forms the starting point for most other methods of time series decomposition. There are two forms of classical decomposition: an additive decomposition and a multiplicative decomposition. These are described below for a time series with seasonal period m (e.g., m = 4 for quarterly data, m = 12 for monthly data, m = 7 for daily data with a weekly pattern).

In classical decomposition, we assume that the seasonal component is constant from year to year. For multiplicative seasonality, the m values that form the seasonal component are sometimes called the “seasonal indices”.

Additive decomposition

Step 1
If m is an even number, compute the trend-cycle component \hat{T}_t using a 2 \times m-MA. If m is an odd number, compute the trend-cycle component \hat{T}_t using an m-MA.
Step 2
Calculate the detrended series: y_t - \hat{T}_t.
Step 3
To estimate the seasonal component for each season, simply average the detrended values for that season. For example, with monthly data, the seasonal component for March is the average of all the detrended March values in the data. These seasonal component values are then adjusted to ensure that they add to zero. The seasonal component is obtained by stringing together these monthly values, and then replicating the sequence for each year of data. This gives \hat{S}_t.
Step 4
The remainder component is calculated by subtracting the estimated seasonal and trend-cycle components: \hat{R}_t = y_t - \hat{T}_t - \hat{S}_t.

Multiplicative decomposition

A classical multiplicative decomposition is similar, except that the subtractions are replaced by divisions.

Step 1
If m is an even number, compute the trend-cycle component \hat{T}_t using a 2 \times m-MA. If m is an odd number, compute the trend-cycle component \hat{T}_t using an m-MA.
Step 2
Calculate the detrended series: y_t / \hat{T}_t.
Step 3
To estimate the seasonal component for each season, simply average the detrended values for that season. For example, with monthly data, the seasonal index for March is the average of all the detrended March values in the data. These seasonal indexes are then adjusted to ensure that they add to m. The seasonal component is obtained by stringing together these monthly indexes, and then replicating the sequence for each year of data. This gives \hat{S}_t.
Step 4
The remainder component is calculated by dividing out the estimated seasonal and trend-cycle components: \hat{R}_{t} = y_t / ( \hat{T}_t \hat{S}_t).

Figure 6.8 shows a classical decomposition of the electrical equipment index. Compare this decomposition with that shown in Figure 6.1. The run of remainder values below 1 in 2009 suggests that there is some “leakage” of the trend-cycle component into the remainder component. The trend-cycle estimate has over-smoothed the drop in the data, and the corresponding remainder values have been affected by the poor trend-cycle estimate.

elecequip |>
  decompose(type = "multiplicative") |>
  autoplot() +
  xlab("Year") +
  ggtitle(
    "Classical multiplicative decomposition
    of electrical equipment index"
  )
Figure 6.8: A classical multiplicative decomposition of the new orders index for electrical equipment.

Comments on classical decomposition

While classical decomposition is still widely used, it is not recommended, as there are now several much better methods. Some of the problems with classical decomposition are summarised below.

  • The estimate of the trend-cycle is unavailable for the first few and last few observations. For example, if m = 12, there is no trend-cycle estimate for the first six or the last six observations. Consequently, there is also no estimate of the remainder component for the same time periods.

  • The trend-cycle estimate tends to over-smooth rapid rises and falls in the data (as seen in the above example).

  • Classical decomposition methods assume that the seasonal component repeats from year to year. For many series, this is a reasonable assumption, but for some longer series it is not. For example, electricity demand patterns have changed over time as air conditioning has become more widespread. Specifically, in many locations, the seasonal usage pattern from several decades ago had its maximum demand in winter (due to heating), while the current seasonal pattern has its maximum demand in summer (due to air conditioning). The classical decomposition methods are unable to capture these seasonal changes over time.

  • Occasionally, the values of the time series in a small number of periods may be particularly unusual. For example, the monthly air passenger traffic may be affected by an industrial dispute, making the traffic during the dispute different from usual. The classical method is not robust to these kinds of unusual values.

6.4 X11 decomposition

Another popular method for decomposing quarterly and monthly data is the X11 method which originated in the US Census Bureau and Statistics Canada.

This method is based on classical decomposition, but includes many extra steps and features in order to overcome the drawbacks of classical decomposition that were discussed in the previous section. In particular, trend-cycle estimates are available for all observations including the end points, and the seasonal component is allowed to vary slowly over time. X11 also has some sophisticated methods for handling trading day variation, holiday effects and the effects of known predictors. It handles both additive and multiplicative decomposition. The process is entirely automatic and tends to be highly robust to outliers and level shifts in the time series.

The details of the X11 method are described in Dagum & Bianconcini (2016). Here we will only demonstrate how to use the automatic procedure in R.

The X11 method is available using the seas() function from the seasonal package for R.

library(seasonal)
elecequip |> seas(x11 = "") -> fit
autoplot(fit) +
  ggtitle("X11 decomposition of electrical equipment index")
Figure 6.9: An X11 decomposition of the new orders index for electrical equipment.

Compare this decomposition with the STL decomposition shown in Figure 6.1 and the classical decomposition shown in Figure 6.8. The X11 trend-cycle has captured the sudden fall in the data in early 2009 better than either of the other two methods, and the unusual observation at the end of 2009 is now more clearly seen in the remainder component.

Given the output from the seas() function, seasonal() will extract the seasonal component, trendcycle() will extract the trend-cycle component, remainder() will extract the remainder component, and seasadj() will compute the seasonally adjusted time series.

For example, Figure 6.10 shows the trend-cycle component and the seasonally adjusted data, along with the original data.

autoplot(elecequip, series = "Data") +
  autolayer(trendcycle(fit), series = "Trend") +
  autolayer(seasadj(fit), series = "Seasonally Adjusted") +
  xlab("Year") +
  ylab("New orders index") +
  ggtitle("Electrical equipment manufacturing (Euro area)") +
  scale_colour_manual(
    values = c("gray", "blue", "red"),
    breaks = c("Data", "Seasonally Adjusted", "Trend")
  )
Figure 6.10: Electrical equipment orders: the original data (grey), the trend-cycle component (red) and the seasonally adjusted data (blue).

It can be useful to use seasonal plots and seasonal sub-series plots of the seasonal component. These help us to visualise the variation in the seasonal component over time. Figure 6.11 shows a seasonal sub-series plot of the seasonal component from Figure 6.9. In this case, there are only small changes over time.

fit |> seasonal() |> ggsubseriesplot() + ylab("Seasonal")
Figure 6.11: Seasonal sub-series plot of the seasonal component from the X11 decomposition of the new orders index for electrical equipment.

6.5 SEATS decomposition

“SEATS” stands for “Seasonal Extraction in ARIMA Time Series” (ARIMA models are discussed in Chapter 8). This procedure was developed at the Bank of Spain, and is now widely used by government agencies around the world. The procedure works only with quarterly and monthly data. So seasonality of other kinds, such as daily data, or hourly data, or weekly data, require an alternative approach.

The details are beyond the scope of this book. However, a complete discussion of the method is available in Dagum & Bianconcini (2016). Here we will only demonstrate how to use it via the seasonal package.

library(seasonal)
elecequip |>
  seas() |>
  autoplot() +
  ggtitle("SEATS decomposition of electrical equipment index")
Figure 6.12: A SEATS decomposition of the new orders index for electrical equipment.

The result is quite similar to the X11 decomposition shown in Figure 6.9.

As with the X11 method, we can use the seasonal(), trendcycle() and remainder() functions to extract the individual components, and seasadj() to compute the seasonally adjusted time series.

The seasonal package has many options for handling variations of X11 and SEATS. See the package website for a detailed introduction to the options and features available.

6.6 STL decomposition

STL is a versatile and robust method for decomposing time series. STL is an acronym for “Seasonal and Trend decomposition using Loess”, while Loess is a method for estimating nonlinear relationships. The STL method was developed by Cleveland et al. (1990).

STL has several advantages over the classical, SEATS and X11 decomposition methods:

  • Unlike SEATS and X11, STL will handle any type of seasonality, not only monthly and quarterly data.

  • The seasonal component is allowed to change over time, and the rate of change can be controlled by the user.

  • The smoothness of the trend-cycle can also be controlled by the user.

  • It can be robust to outliers (i.e., the user can specify a robust decomposition), so that occasional unusual observations will not affect the estimates of the trend-cycle and seasonal components. They will, however, affect the remainder component.

On the other hand, STL has some disadvantages. In particular, it does not handle trading day or calendar variation automatically, and it only provides facilities for additive decompositions.

It is possible to obtain a multiplicative decomposition by first taking logs of the data, then back-transforming the components. Decompositions between additive and multiplicative can be obtained using a Box-Cox transformation of the data with 0 < \lambda < 1. A value of \lambda = 0 corresponds to the multiplicative decomposition while \lambda = 1 is equivalent to an additive decomposition.

The best way to begin learning how to use STL is to see some examples and experiment with the settings. Figure 6.2 showed an example of STL applied to the electrical equipment orders data. Figure 6.13 shows an alternative STL decomposition where the trend-cycle is more flexible, the seasonal component does not change over time, and the robust option has been used. Here, it is more obvious that there has been a down-turn at the end of the series, and that the orders in 2009 were unusually low (corresponding to some large negative values in the remainder component).

elecequip |>
  stl(t.window = 13, s.window = "periodic", robust = TRUE) |>
  autoplot()
Figure 6.13: The electrical equipment orders (top) and its three additive components obtained from a robust STL decomposition with flexible trend-cycle and fixed seasonality.

The two main parameters to be chosen when using STL are the trend-cycle window (t.window) and the seasonal window (s.window). These control how rapidly the trend-cycle and seasonal components can change. Smaller values allow for more rapid changes. Both t.window and s.window should be odd numbers; t.window is the number of consecutive observations to be used when estimating the trend-cycle; s.window is the number of consecutive years to be used in estimating each value in the seasonal component. The user must specify s.window as there is no default. Setting it to be infinite is equivalent to forcing the seasonal component to be periodic (i.e., identical across years). Specifying t.window is optional, and a default value will be used if it is omitted.

The mstl() function provides a convenient automated STL decomposition using s.window=13, and t.window also chosen automatically. This usually gives a good balance between overfitting the seasonality and allowing it to slowly change over time. But, as with any automated procedure, the default settings will need adjusting for some time series.

As with the other decomposition methods discussed in this book, to obtain the separate components plotted in Figure 6.8, use the seasonal() function for the seasonal component, the trendcycle() function for trend-cycle component, and the remainder() function for the remainder component. The seasadj() function can be used to compute the seasonally adjusted series.

6.7 Measuring strength of trend and seasonality

A time series decomposition can be used to measure the strength of trend and seasonality in a time series (Wang et al., 2006). Recall that the decomposition is written as y_t = T_t + S_{t} + R_t, where T_t is the smoothed trend component, S_{t} is the seasonal component and R_t is a remainder component. For strongly trended data, the seasonally adjusted data should have much more variation than the remainder component. Therefore Var(R_t)/Var(T_t + R_t) should be relatively small. But for data with little or no trend, the two variances should be approximately the same. So we define the strength of trend as: F_T = \max\left( 0, 1 - \frac{\text{Var}(R_t)}{\text{Var}(T_t + R_t)} \right). This will give a measure of the strength of the trend between 0 and 1. Because the variance of the remainder might occasionally be even larger than the variance of the seasonally adjusted data, we set the minimal possible value of F_T equal to zero.

The strength of seasonality is defined similarly, but with respect to the detrended data rather than the seasonally adjusted data: F_S = \max\left( 0, 1 - \frac{\text{Var}(R_t)}{\text{Var}(S_{t} + R_t)} \right). A series with seasonal strength F_S close to 0 exhibits almost no seasonality, while a series with strong seasonality will have F_S close to 1 because Var(R_t) will be much smaller than Var(S_{t} + R_t).

These measures can be useful, for example, when you have a large collection of time series, and you need to find the series with the most trend or the most seasonality.

6.8 Forecasting with decomposition

While decomposition is primarily useful for studying time series data, and exploring historical changes over time, it can also be used in forecasting.

Assuming an additive decomposition, the decomposed time series can be written as y_t = \hat{S}_t + \hat{A}_t, where \hat{A}_t = \hat{T}_t + \hat{R}_{t} is the seasonally adjusted component. Or, if a multiplicative decomposition has been used, we can write y_t = \hat{S}_t\hat{A}_t, where \hat{A}_t = \hat{T}_t\hat{R}_{t}.

To forecast a decomposed time series, we forecast the seasonal component, \hat{S}_t, and the seasonally adjusted component \hat{A}_t, separately. It is usually assumed that the seasonal component is unchanging, or changing extremely slowly, so it is forecast by simply taking the last year of the estimated component. In other words, a seasonal naïve method is used for the seasonal component.

To forecast the seasonally adjusted component, any non-seasonal forecasting method may be used. For example, a random walk with drift model, or Holt’s method (discussed in the next chapter), or a non-seasonal ARIMA model (discussed in Chapter 8), may be used.

Example: Electrical equipment manufacturing

fit <- stl(elecequip, t.window = 13, s.window = "periodic", robust = TRUE)
fit |>
  seasadj() |>
  naive() |>
  autoplot() +
  ylab("New orders index") +
  ggtitle("Naive forecasts of seasonally adjusted data")
Figure 6.14: Naïve forecasts of the seasonally adjusted data obtained from an STL decomposition of the electrical equipment orders data.

Figure 6.14 shows naïve forecasts of the seasonally adjusted electrical equipment orders data. These are then “reseasonalised” by adding in the seasonal naïve forecasts of the seasonal component.

This is made easy with the forecast() function applied to the stl object. You need to specify the method being used on the seasonally adjusted data, and the function will do the reseasonalising for you. The resulting forecasts of the original data are shown in Figure 6.15.

fit |> forecast(method = "naive") |> autoplot() + ylab("New orders index")
Figure 6.15: Forecasts of the electrical equipment orders data based on a naïve forecast of the seasonally adjusted data and a seasonal naïve forecast of the seasonal component, after an STL decomposition of the data.

The prediction intervals shown in this graph are constructed in the same way as the point forecasts. That is, the upper and lower limits of the prediction intervals on the seasonally adjusted data are “reseasonalised” by adding in the forecasts of the seasonal component. In this calculation, the uncertainty in the forecasts of the seasonal component has been ignored. The rationale for this choice is that the uncertainty in the seasonal component is much smaller than that for the seasonally adjusted data, and so it is a reasonable approximation to ignore it.

A short-cut approach is to use the stlf() function. The following code will decompose the time series using STL, forecast the seasonally adjusted series, and return the reseasonalised forecasts.

fcast <- stlf(elecequip, method = 'naive')

The stlf() function uses mstl() to carry out the decomposition, so there are default values for s.window and t.window.

As well as the naïve method, several other possible forecasting methods are available with stlf(), as described in the corresponding help file. If method is not specified, it will use the ETS approach (discussed in the next chapter) applied to the seasonally adjusted series. This usually produces quite good forecasts for seasonal time series, and some companies use it routinely for all their operational forecasts.

6.9 Exercises

  1. Show that a 3 \times 5 MA is equivalent to a 7-term weighted moving average with weights of 0.067, 0.133, 0.200, 0.200, 0.200, 0.133, and 0.067.

  2. The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.

    1. Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?
    2. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
    3. Do the results support the graphical interpretation from part a?
    4. Compute and plot the seasonally adjusted data.
    5. Change one observation to be an outlier (e.g., add 500 to one observation), and recompute the seasonally adjusted data. What is the effect of the outlier?
    6. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
  3. Recall your retail time series data (from Exercise 3 in Section 2.10). Decompose the series using X11. Does it reveal any outliers, or unusual features that you had not noticed previously?

  4. Figures 6.16 and 6.17 show the result of decomposing the number of persons in the civilian labour force in Australia each month from February 1978 to August 1995.

    Figure 6.16: Decomposition of the number of persons in the civilian labour force in Australia each month from February 1978 to August 1995.
    Figure 6.17: Seasonal component from the decomposition shown in the previous figure.
    1. Write about 3–5 sentences describing the results of the decomposition. Pay particular attention to the scales of the graphs in making your interpretation.
    2. Is the recession of 1991/1992 visible in the estimated components?
  5. This exercise uses the cangas data (monthly Canadian gas production in billions of cubic metres, January 1960 – February 2005).

    1. Plot the data using autoplot(), ggsubseriesplot() and ggseasonplot() to look at the effect of the changing seasonality over time. What do you think is causing it to change so much?
    2. Do an STL decomposition of the data. You will need to choose s.window to allow for the changing shape of the seasonal component.
    3. Compare the results with those obtained using SEATS and X11. How are they different?
  6. We will use the bricksq data (Australian quarterly clay brick production. 1956–1994) for this exercise.

    1. Use an STL decomposition to calculate the trend-cycle and seasonal indices. (Experiment with having fixed or changing seasonality.)
    2. Compute and plot the seasonally adjusted data.
    3. Use a naïve method to produce forecasts of the seasonally adjusted data.
    4. Use stlf() to reseasonalise the results, giving forecasts for the original data.
    5. Do the residuals look uncorrelated?
    6. Repeat with a robust STL decomposition. Does it make much difference?
    7. Compare forecasts from stlf() with those from snaive(), using a test set comprising the last 2 years of data. Which is better?
  7. Use stlf() to produce forecasts of the writing series with either method="naive" or method="rwdrift", whichever is most appropriate. Use the lambda argument if you think a Box-Cox transformation is required.

  8. Use stlf() to produce forecasts of the fancy series with either method="naive" or method="rwdrift", whichever is most appropriate. Use the lambda argument if you think a Box-Cox transformation is required.

6.10 Further reading

  • A detailed modern discussion of SEATS and X11 decomposition methods is provided by Dagum & Bianconcini (2016).
  • Cleveland et al. (1990) introduced STL, and still provides the best description of the algorithm.
  • For a discussion of forecasting using STL, see Theodosiou (2011).