library(fpp2)
library(tidyverse)
library(seasonal)
autoplot(plastics)
There is an obvious increasing trend and a sinusoidal seasonal pattern.
decompose(plastics, type = 'multiplicative') %>% autoplot()
This is what we expected based on graphical inspection of the data. It should be noted that there is obvious autocorrelation in the remainder.
decompose(plastics, type = 'multiplicative') %>% seasadj() %>% autoplot()
plactics_ol <- plastics
plactics_ol[15] <- plactics_ol[15] *1.5
decomp <- decompose(plactics_ol, type = 'multiplicative') %>% seasadj()
autoplot(decomp)
The outlier has a major affect on the point to which it is applied. It has a small affect on the seasonal component, and therefore, the seasonally adjusted series.
The location of the outlier only affects the trend component points within m/2 points of it (with m being the number of terms in the moving average). This advises how it will affect the seasonal component, and therefore, the seasonally adjusted series.
Outliers in different seasons will have different effects on the seasonally adjusted series. Outliers less than m points of the endpoint will also have different a different effect than an outlier in the middle of the series.
For outliers in the same season more than m points from the end: If the determination of the size of the outlier matches the type of decomostion we’re doing (multiplictive vs additive), then it won’t have a significant effect the seasonal component. In this case, the rest of the seasonally adjusted series should be close to identical for multiplicitive and exactly identical for additive. In our case, if we added a constant, rather than multiplying by 1.5 then the position of the outlier would affect the series.
Given this, if we place the outlier in point 51 (March in the 5th year), it will have a minor affect on all the seasonal adjustments because it is within m points of the end of the series. This is not obvious visually.
plactics_ol <- plastics
plactics_ol[51] <- plactics_ol[51] *1.5
decomp1 <- decompose(plactics_ol, type = 'multiplicative') %>% seasadj()
autoplot(decomp1)
It can be seen when examining the individual values.
First outlier
decomp
## Jan Feb Mar Apr May Jun Jul
## 1 974.7260 988.7027 900.0774 993.9396 993.4010 963.9839 1008.9135
## 2 973.4124 992.9582 1346.6364 1031.5720 1059.9492 1064.9975 1117.1660
## 3 1177.0276 1124.8798 1026.5058 1167.7130 1161.2183 1154.6907 1128.4242
## 4 1249.2782 1221.3386 1087.9801 1227.4822 1228.7310 1238.2882 1286.9059
## 5 1353.0563 1463.9041 1306.0401 1422.2855 1415.8376 1425.5118 1395.1584
## Aug Sep Oct Nov Dec
## 1 999.8875 988.7222 958.8925 986.7504 946.9974
## 2 1109.2502 1097.5798 1098.7839 1083.2914 1089.7122
## 3 1180.7882 1205.6190 1231.8928 1188.9783 1237.2648
## 4 1278.6390 1312.8397 1356.5234 1425.7578 1462.2220
## 5 1322.2196 1250.6353 1203.9145 1137.1511 1225.1703
Second outlier
decomp1
## Jan Feb Mar Apr May Jun Jul
## 1 976.8277 991.4094 895.4402 996.6089 996.2212 967.1192 1002.8691
## 2 975.5112 995.6766 893.1324 1034.3424 1062.9583 1068.4614 1110.4731
## 3 1179.5656 1127.9593 1021.2172 1170.8490 1164.5149 1158.4463 1121.6639
## 4 1251.9719 1224.6822 1082.3749 1230.7787 1232.2192 1242.3157 1279.1961
## 5 1355.9738 1467.9118 1948.9671 1426.1052 1419.8570 1430.1482 1386.8001
## Aug Sep Oct Nov Dec
## 1 994.0923 986.9677 961.3148 989.3231 949.8857
## 2 1102.8212 1095.6322 1101.5597 1086.1158 1093.0357
## 3 1173.9446 1203.4797 1235.0048 1192.0783 1241.0384
## 4 1271.2283 1310.5101 1359.9503 1429.4751 1466.6817
## 5 1314.5563 1248.4161 1206.9559 1140.1160 1228.9070
Test for additive and index less than end - m
plactics_ol1 <- plastics
plactics_ol1[15] <- plactics_ol1[15] + 500
decomp2 <- decompose(plactics_ol1, type = 'additive') %>% seasadj()
plactics_ol2 <- plastics
plactics_ol2[39] <- plactics_ol2[39] + 500
decomp3 <- decompose(plactics_ol2, type = 'additive') %>% seasadj()
near(decomp2, decomp3)
## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## 2 TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## 3 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## 4 TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## 5 TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
retaildata <- read_csv("https://raw.githubusercontent.com/TheFedExpress/Data/master/retail.csv", skip=1)
myts <- ts(retaildata[[12]],frequency=12, start=c(1982,4))
autoplot(myts)
my_x11 <- seas(myts, x11 = '')
autoplot(my_x11)
The remainder term reveals some major outliers in the early 2000s, around the time the dotcom bubble began the burst in the US. There are also some outliers in the early 1980s. X11 also captures the increasing volatility in the seasonal pattern that begins around 2010.
STL Decomposition
stl(myts, t.window = 12, s.window = 'periodic') %>% autoplot()
Compared with x11, the stl decompostion has remainder terms at regular intervals from the 1980s to 1995. These are probably the holidays that stl doesn’t identify. STL also fails to identify the changing seasonal pattern beginning in the 2010s. For monthly data, x11 seems to be greatly preferred over stl.