The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
## Jan Feb Mar Apr May Jun
## 1 742 697 776 898 1030 1107
## [1] 12
# b)
plastics %>% decompose(type="multiplicative") %>%
autoplot() + xlab("Month") +
ggtitle("Classical multiplicative decomposition
of Product sales")
## Jan Feb Mar Apr May Jun Jul
## 1 NA NA NA NA NA NA 976.9583
## 2 1000.4583 1011.2083 1022.2917 1034.7083 1045.5417 1054.4167 1065.7917
## 3 1117.3750 1121.5417 1130.6667 1142.7083 1153.5833 1163.0000 1170.3750
## 4 1208.7083 1221.2917 1231.7083 1243.2917 1259.1250 1276.5833 1287.6250
## 5 1374.7917 1382.2083 1381.2500 1370.5833 1351.2500 1331.2500 NA
## Aug Sep Oct Nov Dec
## 1 977.0417 977.0833 978.4167 982.7083 990.4167
## 2 1076.1250 1084.6250 1094.3750 1103.8750 1112.5417
## 3 1175.5000 1180.5417 1185.0000 1190.1667 1197.0833
## 4 1298.0417 1313.0000 1328.1667 1343.5833 1360.6250
## 5 NA NA NA NA NA
# d)
plastics %>% decompose(type="multiplicative") -> decomp_plast
autoplot(plastics, series="Data") +
autolayer(seasadj(decomp_plast), series="Seasonally Adjusted") +
xlab("Year") + ylab("Sales") +
ggtitle("Monthly sales (in thousands) of product A")
# e)
plastics2 <- plastics
plastics2[40] <- plastics2[40] + 500
plastics2 %>% decompose(type="multiplicative") -> decomp_plast2
autoplot(plastics2, series="Data") +
autolayer(seasadj(decomp_plast2), series="Seasonally Adjusted (Recomputed)") +
xlab("Year") + ylab("Sales") +
ggtitle("Monthly sales (in thousands) of product A")
# f)
plastics3 <- plastics
plastics3[55] <- plastics2[55] + 500
plastics3 %>% decompose(type="multiplicative") -> decomp_plast3
autoplot(plastics3, series="Data") +
autolayer(seasadj(decomp_plast3), series="Seasonally Adjusted (Recomputed)") +
xlab("Year") + ylab("Sales") +
ggtitle("Monthly sales (in thousands) of product A")
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?
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349873A"], frequency=12, start=c(1982,4))
autoplot(myts) +
ggtitle("Monthly Retail Sales")
library(seasonal)
myts_x11 <- seas(myts, x11 = "")
autoplot(myts_x11) +
ggtitle("Monthly Retail Sales (X11)")