Question 2

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?

autoplot(plastics)+ggtitle('Sales of plastic product')

The plot shows a strong seasonality with upward trend. We notice the peak in the middle of each year and then sales decrease gradually.

b.

Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.

plastics %>% 
  decompose(type="multiplicative")%>% 
  autoplot()+ggtitle('Classical multiplicative decomposition of Monthly Sales of plastic product')

c. 

Do the results support the graphical interpretation from part a?

Yes, the result supports my interpretation from part A.The subplot of trend show a steady increase from year 1 to year 5. And the seasonal plot confirm our findings with the peak of every summer.

d. 

Compute and plot the seasonally adjusted data.

Seasonally_adjusted<-seasadj(decompose(plastics,"multiplicative"))
autoplot(plastics,series="Data")+autolayer(Seasonally_adjusted)+ggtitle("Seasonally adjusted data")

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
#Add 500 to the first observation
plastics2[25]<-plastics[25]+500


Seasonally_adjusted2<-seasadj(decompose(plastics2,"multiplicative"))
autoplot(plastics2,series="Data")+autolayer(Seasonally_adjusted2)+ggtitle("Sales of plastic product with outlier")

When we add 500 to index 25,January of the third year, the graph show a spike in the beginning of that year. Comparing to the data after change, the sharp spike of seasonally adjusted data is more obvious.

f.

Does it make any difference if the outlier is near the end rather than in the middle of the time series?

plastics3<-plastics
plastics3[55]<-plastics[55]+500


Seasonally_adjusted3<-seasadj(decompose(plastics3,"multiplicative"))
autoplot(plastics,series="Data")+autolayer(Seasonally_adjusted2)+autolayer(Seasonally_adjusted3)+
ggtitle("Sales of plastic product compare with different outliers")

It did make difference when we change the outlier from the middle of the time series to near the end. We add 500 to July of the year 5, which represents by the blue line. We notice the spike move to the end to match the outlier in year 5.

Question 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[,"A3349874C"],
  frequency=12, start=c(1982,4))
library(seasonal)
myts %>% seas(x11="") -> fit
autoplot(fit) +
  ggtitle("X11 decomposition of Sales of plastic product")

We do detect some outliers in the year 2001 and 2011. When we decompose the data, we notice that sales increase until the year 2011 and then decrease a little bit after that. The decrease might cause by the outliers in 2011.