6 Decomposition
6 Decomposition
Introduction to Time
Series Analysis
2
Outline
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 )
5
Time series decomposition
yt = f (St , Tt , Rt )
5
Time series decomposition
## # A mable: 1 x 1
## STL(value ~ season(window = 7))
## <model>
## 1 <STL>
7
Euro electrical equipment
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
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
11
Seasonal adjustment
12
Euro electrical equipment
120
100
value
80
60
2000 2005 2010
index [1M]
13
Seasonal adjustment
15
History of time series decomposition
16
Moving averages
21
% of GDP
18
15
12
1960 1980 2000
Year
18
Australia economy
19
Australia economy trend
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.
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
23
Estimating the trend-cyle with seasonal
data
24
Classical decomposition
25
Classical additive decomposition
26
Classical additive decomposition
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
28
Outline
29
X-11 decomposition
elecequip %>% model(feasts:::X11(value,type="additive"))%>%
components()%>%autoplot() +
ggtitle("X11 decomposition of electrical equipment index")
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
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
34
X-13ARIMA-SEATS decomposition
elecequip %>% model(feasts:::SEATS(value))%>% components()%>%
autoplot() +
ggtitle("X-13ARIMA-SEATS decomposition of electrical equipment in
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
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
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
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
45
STL decomposition
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
47
Forecasting and decomposition
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
51
Decomposition and prediction intervals