library(seasonal)
library(fpp2)The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
A. Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?
#get information on Plastics
#help("plastics")autoplot(plastics) +
ggtitle("Sales of Product A for a Plastics Manufacture")The data shows us an upward trend over the course of time which are over a range of 5 years. The seasonality of this graph is yearly.
B. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
plastics %>% decompose(type="multiplicative") %>%
autoplot() +
ggtitle("Sales of Product A for a Plastics Manufacturer")C. Do the results support the graphical interpretation from part a?
yes, the data does support the results because in the initial observation there was some seasonality which was not showed in the remainder observation by the cyclic pattern of the remainder.
D. Compute and plot the seasonally adjusted data.
multdecomp <- plastics %>%
decompose(type="multiplicative")
autoplot(plastics, series="Data") +
autolayer(seasadj(multdecomp), series="Seasonally Adjusted") +
ggtitle("Sales of Product A for a Plastics Manufacturer") +
ylab("Monthly Sales of Product A")E. Change one observation to be an outlier (e.g., add 500 to one observation), and recompute the seasonally adjusted data. What is the effect of the outlier?
plastics2<-plastics
plastics2[5]<-plastics[5]+500
plastics2## Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 1 742 697 776 898 1530 1107 1165 1216 1208 1131 971 783
## 2 741 700 774 932 1099 1223 1290 1349 1341 1296 1066 901
## 3 896 793 885 1055 1204 1326 1303 1436 1473 1453 1170 1023
## 4 951 861 938 1109 1274 1422 1486 1555 1604 1600 1403 1209
## 5 1030 1032 1126 1285 1468 1637 1611 1608 1528 1420 1119 1013
plastics2 %>%
stl(t.window=13, s.window="periodic", robust=TRUE) %>%
autoplot()The outlier seem to have made an upward spike within the data.
F. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
From my point of view, it does not make a difference if the outlier is near the end or middle. The outlier will show where it spikes.
6.3 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)myts %>% seas(x11="") -> myts1
autoplot(myts1)+
ggtitle("X11 decomposition")From observing the data presented, I noticed that the X11 shows us seasonal components with the frequency of one year. if you look at 2000 you will see the biggest spikes within the data.