library(fpp2)

Question 6.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 product A for a plastics manufacturer") + 
  ylab("Monthly Sales of Product A") +
  xlab("Year")

Inferece : The Time series shows a seasonality with a frequency of 1 year and an increasing trend.

  1. 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") +
  xlab("Year")

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

Inference: The results of the multiplicative decomposition shows a yearly seasonal component with a frequency of 1 year as previously answered. There is an increasing trend from after the 1st year through five years and then the trend seems to buck down a bit.

d.Compute and plot the seasonally adjusted data.

multi_decom <- plastics %>%
  decompose(type="multiplicative")

autoplot(plastics, series="Data") +
  autolayer(seasadj(multi_decom), series="Seasonally Adjusted") +
  ggtitle("Sales of Product A for a Plastics Manufacturer") + 
  ylab("Monthly Sales of Product A") +
  xlab("Year")

Inference: The seasonally adjusted plot shows the monthly sales of product A with the seasonality removed. The upward trend and remainder make up the seasonally adjusted plot.

  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?
plst <- plastics
plst[20] <- plst[20]+500


multi_decom_spike <- plst %>%
  decompose(type="multiplicative") 

plst %>%
decompose(type="multiplicative") %>% 
autoplot() + 
ggtitle("Sales of Product A for a Plastics Manufacturer")

autoplot(plst, series="Data") +
  autolayer(seasadj(multi_decom_spike), series="Seasonally Adjusted") +
  ggtitle("Sales of Product A for a Plastics Manufacturer with Spike added ") + 
  ylab("Monthly Sales of Product A")

** The introduction of a spike to the data alters the seasonaly adjusted data and it does show the spike there and similarly in the multi decomposition, a minor spike is introduced in seasoanlity part of the chart.

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


multi_decom_spike_end <- plst %>%
  decompose(type="multiplicative") 

plst %>%
decompose(type="multiplicative") %>% 
autoplot() + 
ggtitle("Sales of Product A for a Plastics Manufacturer")

autoplot(plst, series="Data") +
  autolayer(seasadj(multi_decom_spike_end), series="Seasonally Adjusted") +
  ggtitle("Sales of Product A for a Plastics Manufacturer with Spike added ") + 
  ylab("Monthly Sales of Product A")

inference : The introduction of spike to the end of the data shows similar spike in the seasonality data.. however on multi decompsition , the seasonality part of it does not show much variation. Not sure if the inference is correct.

Question 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)
retail <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retail[,"A3349399C"],frequency=12, start=c(1982,4))
myts %>% seas(x11="") -> mytsX11
autoplot(mytsX11) +
  ggtitle("X11 decomposition of Clothing Sales in New South Wales")

Inference : The X-11 decomposition shows a seasonal component with a frequency of 1 year. There is an increasing trend. Chart shows a couple spike in the data between 2000 and 2001. THe longer history of the data seems to take away the spike influence however on a shorter time series, it is kind of evident as above.