R代写-X-11
时间:2022-03-30
Time series decomposition
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
2
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
3
Time series decomposition
Time series data can show a variety of patterns: trend, seasonality
and cycles.
It is useful to split a time series into several components where each
represents an underlying pattern category.
When decomposing a time series into components, we usually
combine the trend and cycle into a one trend-cycle component
(simply trend).
We can think that a time series is consist of three components:
trend-cycle, seasonal and remainder components.
We can expect to see more than one seasonal component, relating
to different seasonal periods (eg. with those observed at least daily).
Often time series decomposition is carried out to improve
understanding of the time series, but can also be used to improve
forecast accuracy.
4
Transformations and adjustments
It is sometimes helpful to transform or adjust the data first before
decomposing.
We discuss four kinds of adjustments:
I Calendar adjustments
I Population adjustments
I Inflation adjustments
I Mathematical transformations
These adjustments and transformations simplify the patterns in data
by removing known sources of variation or making the pattern
consistent across the whole data set.
Simpler patterns are usually easier to model and lead to more
accurate forecasts.
5
Calendar adjustments
Some variation seen in seasonal data may be due to simple calendar
effects.
It is much easier to remove the variation before doing any further
analysis.
If we are studying monthly milk production on a farm, then there will
be variation between the months due to different number of days in
each month in addition to the seasonal variation across the year.
We can remove this variation by computing average milk production
per day in each month.
A similar adjustment can be done for the total monthly sales in a
retail store.
6
Monthly milk production per cow
milk <- fma::milk %>% as_tsibble()
milk %>%
autoplot() +
ylab("Milk production per cow (in pounds)")
600
700
800
900
1965 Jan 1970 Jan 1975 Jan
index [1M]
M
ilk
p
ro
du
ct
io
n
pe
r c
ow
(in
po
un
ds
)
7
Monthly milk production per cow
milk %>%
mutate(days = days_in_month(index)) %>%
mutate(value = value / days) %>%
autoplot(value) +
ylab("Milk production per cow (in pounds)")
20
24
28
32
1965 Jan 1970 Jan 1975 Jan
index [1M]
M
ilk
p
ro
du
ct
io
n
pe
r c
ow
(in
po
un
ds
)
8
Population adjustments
Data that are affected by population changes can be adjusted to give
per-capita data.
We consider the data per person (or per thousand people or per
million people) rather than the total.
The number of hospital beds in a particular region over time can be
affected by the population changes.
We can remove this variation by considering the number of beds per
thousand people.
This will provide a better picture about whether there have been
real increases in the number of beds, or whether the increases are
due to population increases.
9
Per capita adjustments
global_economy %>%
filter(Country == "New Zealand") %>%
autoplot(GDP)
0.0e+00
5.0e+10
1.0e+11
1.5e+11
2.0e+11
1960 1980 2000
Year [1Y]
G
DP
10
Per capita adjustments
global_economy %>%
filter(Country == "New Zealand") %>%
autoplot(GDP / Population)
0
10000
20000
30000
40000
1960 1980 2000
Year [1Y]
G
DP
/P
o
pu
la
tio
n
11
Inflation adjustments
Data which are affected by the value of money are best adjusted
before modelling.
For example, the average cost of a new house in Auckland will have
increased over time due to inflation.
A house which worth $300k this year is not the same as a $300k
house 20–30 years ago.
Financial time series are often adjusted to represent them in dollar
values from a particular year.
The house price data may be stated in year 2000 dollar.
The adjusted house price at year 2000 dollar value is given by
yt/zt ∗ z2000,
yt is the original house price and zt is the price index in year t.
These price indexes are often constructed by government agencies.
12
Inflation adjustments
For consumer goods, a common price index is consumer price index
(CPI).
print_media <- aus_retail %>%
filter(Industry == "Newspaper and book retailing") %>%
index_by(Year = year(Month)) %>%
summarise(Turnover = sum(Turnover))
aus_economy <- global_economy %>%
filter(Country == "Australia")
print_media %>%
left_join(aus_economy, by = "Year") %>%
mutate(Adjusted_turnover = Turnover / CPI * 100) %>%
pivot_longer(c(Turnover, Adjusted_turnover),
names_to = "Type", values_to = "Turnover") %>%
ggplot(aes(x = Year, y = Turnover)) +
geom_line() +
facet_grid(Type ~ ., scales = "free_y") +
labs(x = "Year", y = NULL) 13
Inflation adjustments
Adjusted_turn
o
ve
r
Tu
rn
o
ve
r
1990 2000 2010
3000
3500
4000
4500
5000
2000
3000
4000
Year
14
Inflation adjustments
Adjusted_turn
o
ve
r
Tu
rn
o
ve
r
1990 2000 2010
3000
3500
4000
4500
5000
2000
3000
4000
Year
14
The adjusted turnover is in 2010 Australian dollars (CPI is 100 in
2010).
Australia’s newspaper and book retailing industry has started to
decline much earlier than the original data suggests.
Mathematical transformations
A transformation can be useful if the data shows variation that
increases or decreases with the level of the series.
Denote the original observations by y1, . . . , yT and transformed
observations by w1, . . . ,wT .
Mathematical transformations for stabilizing variation
Logarithm wt = log(yt) ↓
Cube root wt = 3

yt Decreasing
Square root wt =

yt strength
15
Mathematical transformations
A transformation can be useful if the data shows variation that
increases or decreases with the level of the series.
Denote the original observations by y1, . . . , yT and transformed
observations by w1, . . . ,wT .
Mathematical transformations for stabilizing variation
Logarithm wt = log(yt) ↓
Cube root wt = 3

yt Decreasing
Square root wt =

yt strength
15
These are called power
transformations as wt = y
p
t .
Log transformation
Logarithm transformation is useful because it is interpretable:
changes in a log value are relative (or percentage) changes on the
original scale.
rt =
yt − yt−1
yt−1
yt
yt−1
= 1+ rt
log(yt)− log(yt−1) = log(1+ rt) ≈ rt
Taylor series expansion of log(1+ x)
log(1+ x) = x − x
2
2
+
x3
3
− . . . , for − 1 < x < 1.
If x is near zero, then log(1+ x)≈x.
It constrains the forecasts to be positive on the original scale.
16
Mathematical transformation
food <- aus_retail %>%
filter(Industry == "Food retailing") %>%
summarise(Turnover = sum(Turnover))
food %>%
autoplot(Turnover) + ylab("Turnover (Millions of AUD)")
5000
10000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Tu
rn
ov
e
r
(M
illio
ns
of
AU
D)
17
Mathematical transformation
food %>%
autoplot(sqrt(Turnover)) + ylab("Square root turnover")
50
75
100
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Sq
ua
re
ro
ot
tu
rn
ov
e
r
18
Mathematical transformation
food %>%
autoplot(Turnover^(1/3)) + ylab("Cube root turnover")
10
15
20
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Cu
be
ro
ot
tu
rn
ov
e
r
19
Mathematical transformation
food %>%
autoplot(log(Turnover)) + ylab("Log turnover")
7.0
7.5
8.0
8.5
9.0
9.5
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Lo
g
tu
rn
ov
e
r
20
Box-Cox transformations
A useful family of transformations that includes logarithms and
power transformations is the family of Box-Cox transformations:
Box and Cox (1964)
For yt > 0,
wt =
log(yt), λ = 0,yλt −1
λ , λ 6= 0.
Bickel and Doksum (1981)
For λ > 0, yt ∈ R,
wt =
sign(yt)|yt|λ − 1
λ
.
λ = 1: Time series shifts vertically.
λ = 12 : Square root + linear transformation.
λ = 0: Natural logarithm.
λ = −1: Inverse + 1
21
Box-Cox transformations
food %>%
features(Turnover, features = guerrero)
## # A tibble: 1 x 1
## lambda_guerrero
##
## 1 0.0524
Box-Cox transformation parameter tries to balance the seasonal
fluctuations and random variation across the series.
22
Box-Cox transformations
lambda <- food %>%
features(Turnover, features = guerrero) %>%
pull(lambda_guerrero)
food %>% autoplot(box_cox(Turnover, lambda))
9
10
11
12
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
bo
x_
co
x(T
u
rn
ov
e
r,

la
m
bd
a)
23
Transformations
Often no transformation is needed.
Simple transformations make explanation easier and often works
well.
If zeros are present then don’t use the log transformation.
log1p() can be used to handle data with zeros.
Transformations must be reversed to produce forecasts on the
original scale.
Transformations can have large effects on prediction intervals:
I Prediction intervals are no longer symmetric around
back-transformed point forecast.
I A low value of λ can give large prediction intervals.
24
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
25
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.
26
Time series decomposition
Additive decomposition is suitable if the magnitude of the seasonal
fluctuations, or the variation around the trend-cycle does not vary
with the level.
Multiplicative decomposition is suitable if the variation in the
seasonal pattern, or the variation around the trend-cycle does vary
proportional to the level of the series.
Alternative to multiplicative decomposition: first transform the data
until the variation in the series appears to be stable over time and
then use an additive decomposition.
Logs turn multiplicative relationship into an additive relationship.
yt = St × Tt × Rt =⇒ log(yt) = log(St) + log(Tt) + log(Rt).
27
US retail employment
us_retail_employment <- us_employment %>%
filter(year(Month) >= 1990, Title == "Retail Trade") %>%
select(-Series_ID)
us_retail_employment %>%
autoplot(Employed) + ylab("Persons (in thousands)")
13000
14000
15000
16000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Pe
rs
o
n
s
(in
th
ou
sa
nd
s)
28
US retail employment
us_retail_employment %>%
model(stl = STL(Employed))
## # A mable: 1 x 1
## stl
##
## 1
29
US retail employment
dcmp <- us_retail_employment %>%
model(stl = STL(Employed))
components(dcmp) %>% print(n = 6)
## # A dable: 357 x 7 [1M]
## # Key: .model [1]
## # : Employed = trend + season_year + remainder
## .model Month Employed trend season_year remainder
##
## 1 stl 1990 Jan 13256. 13288. -33.0 0.836
## 2 stl 1990 Feb 12966. 13269. -258. -44.6
## 3 stl 1990 Mar 12938. 13250. -290. -22.1
## 4 stl 1990 Apr 13012. 13231. -220. 1.05
## 5 stl 1990 May 13108. 13211. -114. 11.3
## 6 stl 1990 Jun 13183. 13192. -24.3 15.5
## # ... with 351 more rows, and 1 more variable:
## # season_adjust
30
US retail employment
components(dcmp) %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−250
0
250
500
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
31
US retail employment
The plots show each component on different panels on it’s own
scale.
We need those gray bars to indicate relative scales of the
components for comparison.
Each gray bar represents the same length but because the plots are
on different scales the size vary.
The variation in the trend component is largest and remainder
component is smallest.
If we shrunk the bottom three panels until their bars became the
same size as the first panel, then all the panels would be on the
same scale.
32
US retail employment
us_retail_employment %>%
autoplot(Employed, color = "gray") +
autolayer(components(dcmp), trend, color = "red") +
ylab("Persons (in thousands)")
13000
14000
15000
16000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Pe
rs
o
n
s
(in
th
ou
sa
nd
s)
33
US retail employment
components(dcmp) %>% gg_subseries(season_year)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
stl
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
19
90
20
00
20
10
20
20
−250
0
250
500
Month
se
a
so
n
_
ye
a
r
34
Seasonal adjustment
If the variation due to seasonality is not the primary interest, we can
remove the seasonal component giving seasonally adjusted data.
For additive decomposition:
yt − St = Tt + Rt
For multiplicative decomposition:
yt/St = Tt × Rt
35
Seasonal adjustment
us_retail_employment %>%
autoplot(Employed, color = "gray") +
autolayer(components(dcmp), season_adjust, color = "blue") +
ylab("Persons (in thousand)")
13000
14000
15000
16000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Pe
rs
o
n
s
(in
th
ou
sa
nd
)
36
Seasonal adjustment
Seasonally adjusted data contain the trend-cycle and remainder
components.
They are not smooth, so upturns and downturns can be misleading.
It is better to use the trend-cycle component to look for turning
points.
37
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
38
Moving averages
A moving average of orderm (m-MA)
xt =
1
m
k∑
j=−k
yt+j, m = 2k + 1.
It averages values which are within k periods from t.
The average eliminates some of the randomness in the data.
Useful to estimate the trend-cycle component.
39
Moving averages
global_economy %>%
filter(Country == "Australia") %>%
autoplot(Exports) +
ylab("% of GDP")
12
15
18
21
1960 1980 2000
Year [1Y]
%
o
f G
DP
40
Moving averages
Year Exports 5-MA
1960 13.0 NA
1961 12.4 NA
1962 13.9 13.5
1963 13.0 13.5
1964 14.9 13.6
1965 13.2 13.4
2012 21.5 20.8
2013 20.0 20.8
2014 21.1 20.4
2015 20.0 20.3
2016 19.3 NA
2017 21.3 NA
41
Moving averages
aus_exports <- global_economy %>%
filter(Country == "Australia") %>%
mutate(
`5-MA` = slider::slide_dbl(Exports, mean,
.before = 2, .after = 2, .complete = TRUE)
)
aus_exports %>%
autoplot(Exports) +
autolayer(aus_exports, `5-MA`, color = "red") +
ylab("Exports (% of GDP)")
42
Moving averages
12
15
18
21
1960 1980 2000
Year [1Y]
Ex
po
rts
(%
of
G
DP
)
43
Moving averages
12
15
18
21
1960 1980 2000
Year [1Y]
Ex
po
rts
(%
of
G
DP
)
43
The red line is smoother than the original series.
Moving averages
7−MA 9−MA
3−MA 5−MA
1960 1980 2000 1960 1980 2000
12
15
18
21
12
15
18
21
Year [1Y]
44
Moving averages
7−MA 9−MA
3−MA 5−MA
1960 1980 2000 1960 1980 2000
12
15
18
21
12
15
18
21
Year [1Y]
44
A larger moving average order implies a
smoother curve.
We have considered odd orders here because
they are symmetric.
Moving averages of moving averages
It is possible to apply a moving average to a moving average.
We can use this to make an even-order moving average symmetric.
eg. we can take a moving average of order 4, and then apply another
moving average of order 2 to make it symmetric.
This gives a weighted average of observations.
xt =
1
2
[
1
4
(yt−2 + yt−1 + yt + yt+1) +
1
4
(yt−1 + yt + yt+1 + yt+2)
]
=
1
8
yt−2 +
1
4
yt−1 +
1
4
yt +
1
4
yt+1 +
1
8
yt+2
45
Moving averages of moving averages
Centred moving averages are useful to estimate the trend-cycle
component from seasonal data.
When we apply 2× 4-MA to quarterly data, each quarter of the year
receives an equal weight.
As a result seasonal variation is averaged out.
Same effect can be seen when using 2× 8-MA or 2× 12-MA to
quarterly data.
If the seasonal period is even and of orderm, we use 2×m-MA.
If the seasonal period is odd and of orderm, we usem-MA.
eg: Monthly data (2× 12-MA) and daily data (7-MA).
46
US retail employment
us_retail_employment_ma <- us_retail_employment %>%
mutate(
`12-MA` = slider::slide_dbl(Employed, mean,
.before = 5, .after = 6, .complete = TRUE),
`2x12-MA` = slider::slide_dbl(`12-MA`, mean,
.before = 1, .after = 0, .complete = TRUE)
)
us_retail_employment_ma %>%
autoplot(Employed, color = "gray") +
autolayer(us_retail_employment_ma, `2x12-MA`, color = "red") +
ylab("Persons (in thousands)")
47
US retail employment
13000
14000
15000
16000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Pe
rs
o
n
s
(in
th
ou
sa
nd
s)
48
US retail employment
13000
14000
15000
16000
1990 Jan 2000 Jan 2010 Jan 2020 Jan
Month [1M]
Pe
rs
o
n
s
(in
th
ou
sa
nd
s)
48
Except 24, 36, etc other choices can result in a
smooth line that is contaminated by seasonality.
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
49
Classical decomposition
Originated in the 1920s.
It is a relatively simple procedure.
There are two forms: an additive decomposition and a multiplicative
decomposition.
We assume that the seasonal component doesn’t vary from year to
year.
50
Classical decomposition
1 Ifm (seasonal period) is an even number, use 2×m-MA to estimate the trend-cycle
component (Tˆt). Ifm is an odd number, usem-MA.
2 Calculate the detrended series:
Additive: yt − Tˆt
Multiplicative: yt/Tˆt
3 Estimate the seasonal component for each season by averaging the detrended values for that
season. The component values are adjusted to ensure they
Additive: sum to zero.
Multiplicative: sum tom.
4 Replicate the sequence for each year of data to get Sˆt.
5 The remainder component is calculated by:
Additive: Rˆt = yt − Tˆt − Sˆt.
Multiplicative: Rˆt = yt/(Tˆt Sˆt).
51
US retail employment
us_retail_employment %>%
model(classical_decomposition(Employed, type = "additive")) %>%
components() %>%
autoplot()
Em
ployed
trend
se
a
so
n
al
ra
ndom
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−200
0
200
400
600
−100
−50
0
50
100
Month
Employed = trend + seasonal + random
Classical decomposition
52
Drawbacks of classical decomposition
The estimate of trend-cycle is unavailable for the first few and last
few observations.
The trend-cycle estimate can over-smooth rapid changes in the data.
This method assumes that the seasonal component is fixed and
repeats from year to year.
Not robust to unusual observations.
53
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
54
X-11 and X-11-ARIMA decomposition
Original X-11 software was developed by US Census Bureau in 1960s.
It overcomes the drawbacks of classical decomposition:
I Trend-cycle estimates are available for all observations.
I The seasonal component is allowed to vary with time.
I Relatively to robust to outliers.
Poor seasonally adjusted data at the end of the series.
Statistics Canada introduced X-11-ARIMA to address this drawback.
I Model original series with an ARIMA model and extend the original
series 1–3 years with forecasts from the ARIMA model
I Each component is estimated with moving averages.
55
X-12-ARIMA, TRAMO-SEATS and X-13-ARIMA-SEATS
X-12-ARIMA can estimate deterministic components such as trading day
variations, moving holiday effects, outliers and level shifts.
I Uses regression model with ARIMA errors.
TRAMO-SEATS developed at the Bank of Spain.
TRAMO (Time series regression with ARIMA noise, missing observations
and outliers)
SEATS (Signal extraction in ARIMA time series)
Firstly, TRAMO estimates the deterministic components via regression and
removed from the original data.
Secondly, SEATS estimates the trend-cycle and seasonal components from
the ARIMA model fitted to the data from previous step.
X-13-ARIMA-SEATS integrates an enhanced version of X-12-ARIMA with an
enhanced version of SEATS.
56
X-13-ARIMA-SEATS
Only available for quarterly and monthly data.
Available through seasonal package for R.
A new function will be available soon via feasts package.
57
Outline
1 Transformations and adjustments
2 Time series components
3 Moving averages
4 Classical decomposition
5 X-11 and SEATS decomposition
6 STL decomposition
58
STL decomposition
STL: Seasonal and trend decomposition using loess.
Very versatile and robust approach.
Can handle any type of seasonality.
Seasonal component can allowed to vary with time, and the rate of
change can be controlled by the user.
Smoothness of the trend-cycle can be controlled by the user.
Robust to outliers so that seasonal and trend-cycle will not get
affected. But these occasional unusual observations can affect the
remainder component.
STL does not allow for trading day or moving holiday effects.
Decomposition is additive.
Take logs to get multiplicative decomposition.
Decompositions between additive and multiplicative can be
obtained using a Box-Cox transformation of data where 0 < λ < 1.
59
US retail employment
us_retail_employment %>%
model(STL(Employed)) %>%
components() %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−250
0
250
500
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
60
US retail employment
us_retail_employment %>%
model(STL(Employed ~ trend(window = 7) + season(window = "periodic"),
robust = TRUE)) %>% components() %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−200
0
200
400
600
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
61
STL decomposition
Trend and seasonal windows should be odd numbers.
trend(window = ?) controls wiggliness of the trend component.
Trend window is the number of consecutive observations to be used
for estimating the trend-cycle.
season(window = ?) controls variation on the seasonal
component.
Season window is the number of consecutive years to be used for
estimating each value in the seasonal component.
season(window = "periodic") is equivalent to an infinite
window.
Smaller windows allow for more rapid changes.
62
STL decomposition
STL algorithm updates trend and seasonal components iteratively.
Starts with Tˆt = 0.
Uses a mixture of loess and moving averages to refine the trend and
seasonal estimates.
Trend window controls loess bandwidth applied to deseasonalized
data.
Seasonal window controls loess bandwidth applied to detrended
subseries.
Robustness weights are based on remainder.
Default season window = 13.
Default trend window = nextodd(ceiling((1.5 * period)/(1
-(1.5/s.window)))).
63
US retail employment
us_retail_employment %>%
model(STL(Employed)) %>%
components() %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−250
0
250
500
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
64
US retail employment
us_retail_employment %>%
model(STL(Employed)) %>%
components() %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−250
0
250
500
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
64
Trend-cycle is over-smooth.
The 2008 global financial crisis has leaked into the
remainder component.
The default settings need to be adjusted.
US retail employment
us_retail_employment %>%
model(STL(Employed ~ trend(window = 7) + season(window = "periodic"),
robust = TRUE)) %>% components() %>% autoplot()
Em
ployed
trend
se
a
so
n
_ye
a
r
re
m
ainder
1990 Jan 2000 Jan 2010 Jan 2020 Jan
13000
14000
15000
16000
13000
14000
15000
16000
−200
0
200
400
600
−100
−50
0
50
100
Month
Employed = trend + season_year + remainder
STL decomposition
65


essay、essay代写