0% found this document useful (0 votes)
23 views55 pages

6 Decomposition

Uploaded by

George Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views55 pages

6 Decomposition

Uploaded by

George Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

STAT481/581:

Introduction to Time
Series Analysis

Ch3. Time series decomposition


OTexts.org/fpp3/
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

2
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

3
Time series patterns

Recall
Trend pattern exists when there is a long-term
increase or decrease in the data.
Cyclic pattern exists when data exhibit rises and
falls that are not of fixed period (duration
usually of at least 2 years).
Seasonal pattern exists when a series is influenced
by seasonal factors (e.g., the quarter of
the year, the month, or day of the week).

4
Time series decomposition

yt = f (St , Tt , Rt )

where yt = data at period t


Tt = trend-cycle component at period t
St = seasonal component at period t
Rt = remainder component at period t

5
Time series decomposition

yt = f (St , Tt , Rt )

where yt = data at period t


Tt = trend-cycle component at period t
St = seasonal component at period t
Rt = remainder component at period t
Additive decomposition: yt = St + Tt + Rt .
Multiplicative decomposition: yt = St × Tt × Rt .

5
Time series decomposition

Additive model appropriate if magnitude of seasonal


fluctuations does not vary with level.
If seasonal are proportional to level of series, then
multiplicative model appropriate.
Multiplicative decomposition more prevalent with
economic series
Alternative: use a Box-Cox transformation, and then
use additive decomposition.
Logs turn multiplicative relationship into an additive
relationship:

yt = S t × Tt × E t ⇒ log yt = log St + log Tt + log Rt . 6


Decomposition

dcmp <- elecequip %>% model(STL(value ~ season(window = 7)))


dcmp

## # A mable: 1 x 1
## STL(value ~ season(window = 7))
## <model>
## 1 <STL>

7
Euro electrical equipment

dcmp %>% components()%>% autoplot() + xlab("Year")

STL decomposition
value = trend + season_year + remainder

120

value
100

80

60
110

100

trend
90

80

10

season_year
0

−10

−20

remainder
0
−4

1995 2000 2005 2010 8


Year
value

60
80
100
120
2000

Jan
2005
2010

2000

Feb
2005
2010

2000
2005 Mar
2010

2000
Apr

2005
2010

2000
May

2005
2010

2000
Jun

2005
gg_subseries(value)

2010

index
2000
Jul

2005
2010
Euro electrical equipment

2000
Aug

2005
2010

2000
Sep

2005
2010

2000
Oct

2005
2010
dcmp %>% components(season_year)%>%

2000
Nov

2005
2010

2000
Dec

2005
2010 STL(value ~ season(window = 7))
9
Euro electrical equipment

autoplot(elecequip) +
autolayer(components(dcmp), trend)

120

100
value

80

60
2000 2005 2010
index [1M]

10
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

11
Seasonal adjustment

Useful by-product of decomposition: an easy


way to calculate seasonally adjusted data.
Additive decomposition: seasonally adjusted
data given by
yt − St = Tt + Rt
Multiplicative decomposition: seasonally
adjusted data given by
yt /St = Tt × Rt

12
Euro electrical equipment

dcmp <- elecequip %>% model(STL(value ~ season(window=7)))


elecequip %>% autoplot(value) +
autolayer(components(dcmp), trend + remainder)

120

100
value

80

60
2000 2005 2010
index [1M]
13
Seasonal adjustment

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.
We use estimates of S based on past values to
seasonally adjust a current value.
Seasonally adjusted series reflect remainders as
well as trend. Therefore they are not “smooth”. 14
History of time series decomposition

Classical method originated in 1920s.


Census II method introduced in 1957. Basis for X-11
method and variants (including X-12-ARIMA,
X-13-ARIMA)
STL method introduced in 1983
TRAMO/SEATS introduced in 1990s.

15
History of time series decomposition

Classical method originated in 1920s.


Census II method introduced in 1957. Basis for X-11
method and variants (including X-12-ARIMA,
X-13-ARIMA)
STL method introduced in 1983
TRAMO/SEATS introduced in 1990s.
National Statistics Offices
ABS uses X-12-ARIMA
US Census Bureau uses X-13ARIMA-SEATS
Statistics Canada uses X-12-ARIMA
ONS (UK) uses X-12-ARIMA
EuroStat use X-13ARIMA-SEATS 15
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

16
Moving averages

The first step in a classical decomposition is to


use a moving average method to estimate the
trend-cycle.
A moving average of order m can be written as
1 X k
T̂t = yt+j
m j=−k
where m = 2k + 1. We call this an m-MA.
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. 17
Australia economy plot

global_economy %>% filter(Country == "Australia") %>%


autoplot(Exports) + xlab("Year") + ylab("% of GDP") +
ggtitle("Total Australian exports")

Total Australian exports

21
% of GDP

18

15

12
1960 1980 2000
Year
18
Australia economy

aus_exports <- global_economy %>%


filter(Country == "Australia") %>%
mutate(5-MA = slide_dbl(Exports, mean,
.size = 5, .align = "center"))

19
Australia economy trend

## Warning: Removed 4 rows containing missing values (geom_pa

Total Australian exports

21
Exports (% of GDP)

18

15

12
1960 1980 2000
Year

20
Moving averages of moving averages
m can be even but the moving average would no longer be
symmetric
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.

beer <- aus_production %>%


filter(year(Quarter) >= 1992) %>%
select(Quarter, Beer)
beer_ma <- beer %>%
mutate(
4-MA = slide_dbl(Beer, mean, .size = 4,
.align = "center-left"),
2x4-MA = slide_dbl(4-MA, mean, .size = 2,
.align = "center-right")
) 21
Moving averages of moving averages

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”–written as 2 × 4-MA.

1 1 1
 
T̂t = (yt−2 + yt−1 + yt + yt+1 ) + (yt−1 + yt + yt+1 + yt+2 )
2 4 4
It is now a weighted average of observations that is symmetric.

22
Estimating the trend-cyle with seasonal
data

The most common use of centred moving averages is for


estimating the trend-cycle from seasonal data.
For quarterly data, we can use 2 × 4-MA
1 1 1 1 1
T̂t = yt−2 + yt−1 + yt + yt+1 + yt+2
8 4 4 4 8
Consequently, the seasonal variation will be averaged out and
the resulting values of
T̂t will have little or no seasonal variation remaining.

23
Estimating the trend-cyle with seasonal
data

For monthly data, we can use 2 × 12-MA to estimate the


trend-cycle.
For weekly data, we can use 7-MA.

24
Classical decomposition

There are two forms of classical decomposition:


an additive decomposition and a multiplicative
decomposition.
Let m be the seasonal period.

25
Classical additive decomposition

step 1: If is an even number, compute the trend-cycle


component T̂t using 2 × m-MA. If m is an odd number, use
m-MA.
Step 2: Calculate the detrended series: Tt − T̂t .
Step 3: To estimate the seasonal component for each season,
simply average the detrended values for that season.
Step 4: The remainder component is calculated by subtracting
the estimated seasonal and trend-cycle components.

26
Classical additive decomposition

elecequip %>% model(classical_decomposition(value,


type = "additive")) %>% components() %>% autoplot() + xlab("Y
ggtitle("Classical additive decomposition of electrical equi

Classical additive decomposition of electrical equipment index


value = trend + seasonal + random
120

value
100
80
60
110

trend
100
90
80
10

seasonal
0

−10

8
4

random
0
−4
27
1995 2000 2005 2010
Classical additive decomposition

The trend-cycle estimate tends to over-smooth


rapid rises and falls in the data.
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.
The classical method is not robust to unusual
values.

28
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

29
X-11 decomposition
elecequip %>% model(feasts:::X11(value,type="additive"))%>%
components()%>%autoplot() +
ggtitle("X11 decomposition of electrical equipment index")

X11 decomposition of electrical equipment index


value = trend + seasonal + irregular
120

value
100
80
60
110

trend
100
90
80
10

seasonal
0

−10

irregular
4
0
−4
30
1995 2000 2005 2010
Advantages of X-11

Details are in Dagum, E. B., & Bianconcini, S.


(2016). Seasonal adjustment methods and real
time trend-cycle estimation. Springer
Relatively robust to outliers and level shifts.
Has some sophisticated methods for handling
trading day variation, holiday effects and the
effects of known predictors.
Completely automated choices for trend and
seasonal changes
Very widely tested on economic data over a long
period of time. 31
Disadvantages of X-11

No prediction/confidence intervals
Ad hoc method with no underlying model
Only developed for quarterly and monthly data

32
Extensions: X-12-ARIMA and X-13-
ARIMA

The X-11, X-12-ARIMA and X-13-ARIMA


methods are based on Census II decomposition.
These allow adjustments for trading days and
other explanatory variables.
Known outliers can be omitted.
Level shifts and ramp effects can be modelled.
Missing values estimated and replaced.
Holiday factors (e.g., Easter, Labour Day) can
be estimated.
33
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

34
X-13ARIMA-SEATS decomposition
elecequip %>% model(feasts:::SEATS(value))%>% components()%>%
autoplot() +
ggtitle("X-13ARIMA-SEATS decomposition of electrical equipment in

X−13ARIMA−SEATS decomposition of electrical equipment index


value = trend * seasonal * irregular
120

value
100
80
60
110

trend
100
90
80
1.1

seasonal
1.0

0.9

1.10

irregular
1.05
1.00
0.95 35
1995 2000 2005 2010
X-13ARIMA-SEATS decomposition
Total employment in US retail

120
Persons (thousands)

colour
100
Data
Seasonally Adjusted
Trend

80

60
2000 2005 2010
Year

36
Seasonal

0.9
1.0
1.1
2000

Jan
2005 fit %>%
2010

2000

Feb
2005
2010

2000 Mar
2005
2010

2000
Apr

2005
2010

2000
May

2005
2010

2000
Jun

2005
2010

index
2000
Jul

2005
2010

2000
Aug

2005
2010

2000
Sep

2005
2010
gg_subseries(seasonal) + ylab("Seasonal")

2000
Oct

2005
2010

2000
X-13ARIMA-SEATS decomposition

Nov

2005
2010

2000
Dec

2005
2010 feasts:::SEATS(value)
37
(Dis)advantages of X-13ARIMA-SEATS

Advantages
Model-based
Smooth trend estimate
Allows estimates at end points
Allows changing seasonality
Developed for economic data

38
(Dis)advantages of X-13ARIMA-SEATS

Advantages
Model-based
Smooth trend estimate
Allows estimates at end points
Allows changing seasonality
Developed for economic data
Disadvantages
Only developed for quarterly and monthly data

38
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

39
STL decomposition
STL: “Seasonal and Trend decomposition using
Loess”
Very versatile and robust.
Unlike X-12-ARIMA, STL will handle any type of
seasonality.
Seasonal component allowed to change over time,
and rate of change controlled by user.
Smoothness of trend-cycle also controlled by user.
Robust to outliers
Not trading day or calendar adjustments.
Only additive.
Take logs to get multiplicative decomposition.
Use Box-Cox transformations to get other
40
decompositions.
STL decomposition

dcmp <- elecequip %>%


model(STL(value ~ season(window = 5), robust = TRUE))
autoplot(components(dcmp)) +
ggtitle("STL decomposition of electrical equipment index")

STL decomposition of electrical equipment index


value = trend + season_year + remainder
120

value
100
80
60
110
100

trend
90
80

season_year
10
0
−10
−20

remainder
10
0
−10
−20 41
1995 2000 2005 2010
STL decomposition

fit <- elecequip %>%


model(STL(value ~ season(window="periodic"), robust=TRUE))
autoplot(components(fit)) +
ggtitle("STL decomposition of electrical equipment index")

STL decomposition of electrical equipment index


value = trend + season_year + remainder
120

value
100
80
60
110

trend
100
90
80
10

season_year
0
−10

10

remainder
5
0
−5
−10 42
1995 2000 2005 2010
STL decomposition

elecequip %>%
model(STL(value ~ season(window = 5)))

elecequip %>%
model(STL(value ~ trend(window=15) + season(window="periodic"),
robust = TRUE))

43
STL decomposition

trend(window = ?) controls wiggliness of


trend component.
season(window = ?) controls variation on
seasonal component.
Smaller values of both parameters allow for more
rapid changes.
Both trend and seasonal windows should be odd
numbers;
Trend/season window is the number of
consecutive observations to be used when
estimating the trend-cycle/season component.
44
STL decomposition

Setting the seasonal window to be infinite is


equivalent to forcing the seasonal component to
be periodic season(window=‘periodic’)(i.e.,
identical across years).
By default, the STL() function provides a
convenient automated STL decomposition using
a seasonal window of season(window=13), and
the trend window chosen automatically from the
seasonal period.

45
STL decomposition

elecequip %>% model(STL(value)) %>% components() %>%auto

STL decomposition
value = trend + season_year + remainder
120

value
100
80
60
110

trend
100
90
80

season_year
10
0
−10

remainder
5
0
−5
1995 2000 2005 2010
index

STL() chooses season(window=13) by default


46
Can include transformations.
Outline

1 Time series components


2 Seasonal adjustment
3 Classical decomposition
4 X-11 decomposition
5 X-13ARIMA-SEATS decomposition
6 STL decomposition
7 Forecasting and decomposition

47
Forecasting and decomposition

Forecast seasonal component by repeating the


last year
Forecast seasonally adjusted data using
non-seasonal time series method.
Combine forecasts of seasonal component with
forecasts of seasonally adjusted data to get
forecasts of original data.
Sometimes a decomposition is useful just for
understanding the data before building a
separate forecasting model.
48
Electrical equipment
dcmp <- elecequip %>%
model(STL(value ~ trend(window=13) + season(window="periodic")))%
dcmp %>%
model(NAIVE(season_adjust)) %>% forecast() %>%
autoplot(dcmp) + ylab("New orders index") +
ggtitle("ETS forecasts of seasonally adjusted data")

ETS forecasts of seasonally adjusted data

110
New orders index

.level
90 80
95

70

49
2000 2005 2010 2015
Electrical equipment
elecequip%>% model(decomposition_model(STL(
value ~ trend(window = 13) + season(window = "periodic")),
NAIVE(season_adjust)))%>% forecast() %>%
autoplot(elecequip) + ylab("New orders index") + xlab("Year")

120
New orders index

100 .level
80

80 95

60

2000 2005 2010 2015


Year
50
Decomposition models

decomposition_model() creates a decomposition


model
You must provide a method for forecasting the
season_adjust series.
A seasonal naive method is used by default for
the seasonal components.

51
Decomposition and prediction intervals

It is common to take the prediction intervals


from the seasonally adjusted forecasts and
modify them with the seasonal component.
This ignores the uncertainty in the seasonal
component estimate.
It also ignores the uncertainty in the future
seasonal pattern.
The fable package combines the uncertainty from
both the seasonally adjusted and seasonal forecasts.
When using decomposition_model() to produce
forecasts, the seasonal uncertainty is not ignored! 52

You might also like