library(fpp2)
## -- Attaching packages ------------------------------------------------------------------------------------------------------------------------------------------------------ fpp2 2.4 --
## v ggplot2   3.1.0     v fma       2.4  
## v forecast  8.12      v expsmooth 2.3
## 

(6.2)

The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.

  1. Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?
autoplot(plastics)

The plot shows there’s an overall upward trend over the five years. There appears to be a yearly seasonality.

  1. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
plastics %>%
decompose(type="multiplicative") %>% 
autoplot() + 
ggtitle("Product A Sales")

  1. Do the results support the graphical interpretation from part a?

Yes. The results support the graphical interpretation from part a. As you can see, seasonality is yearly and there’s an upward trend.

  1. Compute and plot the seasonally adjusted data.
decompose_mult <- plastics %>%
  decompose(type="multiplicative")

autoplot(plastics, series="Data") +
  autolayer(seasadj(decompose_mult), series="Seasonally Adjusted") +
  ggtitle("Product A Sales") + 
  ylab("Monthly Sales")

Seasonally adjusted plot shows the trend-cycle and remainder component of the data. The seasonal component of the data has been removed.

  1. 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[20] <- plastics2[20]+500

decompose_mult <- plastics2 %>%
  decompose(type="multiplicative") 

autoplot(plastics2, series='Data') +
  autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')

I introduced an outlier on the 20th data point. And the outlier is visible in the seasonally adjusted plot. This is seen as a spike in the plot where the outlier was introduced.

  1. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
plastics2 <- plastics
plastics2[5] <- plastics2[5]+500

decompose_mult <- plastics2 %>%
  decompose(type="multiplicative") 

autoplot(plastics2, series='Data') +
  autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')

I introduced an outlier on the 5th data point. The effect is similar in that the location of the spike moved towards the beginning of the plot. But the overall trend/shape of the plot is the same.

plastics2 <- plastics
plastics2[50] <- plastics2[50]+500

decompose_mult <- plastics2 %>%
  decompose(type="multiplicative") 

autoplot(plastics2, series='Data') +
  autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')

I introduced an outlier on th 50th data point. The effect is similar in that the location of the spike moved towards the end of the plot. But the overall trend/shape of the plot is the same.

Based on my observation, the effect is similar whether the outlier is towards the beginning, middle, or end of the plot. The outlier is seen as a spike in the plot, but the overall shape of the plot remains the same.


(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?

library(seasonal)
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
#Turnover ;  New South Wales ;  Supermarket and grocery stores ;
myts <- ts(retaildata[,"A3349335T"],frequency=12, start=c(1982,4))

myts %>% seas(x11="") -> myts_x11
autoplot(myts_x11) +
  ggtitle("X11 decomposition of Supermarket and Grocery Stores")

The plot shows seasonality and upward trend cycle. I don’t particularly notice any obvious outliers. It’s interesting that the magnitude of seasonal plot appears to slowly decrease, plateau for a bit and then slowly increase again.