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) + scale_y_continuous(labels=comma) +
  labs(title='Monthly Sales of Plastic Product "A"',
       y="Sales", x="Time")

ggseasonplot(plastics) +
  labs(y="Sales", x="Month") +
  guides(colour=guide_legend(title="Year"))

ggsubseriesplot(plastics) +
  labs(title='Subseries Plot',
       y="Sales", x="Month")

  • Looking at these plots, there is definitely a seasonality. Sales picks up in April, peaks near August, then then declines.

  • There is also a trend, shown in the Seasonal Plot, where sales have been increasing each year. However, there appears to be something in the 5th year causing a premature decline in June and a decrease by year-end lower than it began. This may indicate that the upward trend is about to reverse.

b) Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
decomp <- decompose(plastics, type="multiplicative")

autoplot(decomp) + labs(title="Classic Multiplicative Decomposition",
                        x="Time")

c) Do the results support the graphical interpretation from part a?
  • Yes, the decomposition shows the trend and the start of that trend reversal seen in the seasonal plot above. It also captures the seasonality rather well.
d) Compute and plot the seasonally adjusted data.
sadjust <- seasadj(decomp)

autoplot(sadjust) + scale_y_continuous(labels=comma) +
  labs(title='Monthly Sales of Plastic Product "A"',
       subtitle = "Seasonally-adjusted (Classic Multiplicative)",
       y="Sales", x="Time")

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?
# Change Aug in Year 5
plastics2 <- plastics

plastics2[length(plastics2)-4] <- plastics[length(plastics)-4]+500
decomp2 <- decompose(plastics2, type="multiplicative")
sadjust2 <- seasadj(decomp2)

autoplot(sadjust2) + scale_y_continuous(labels=comma) +
  labs(title='Monthly Sales of Plastic Product "A"',
       subtitle = "Seasonally-adjusted (End Outlier)",
       y="Sales", x="Time")

  • The outlier we added is shown in the seasonally-adjusted data, as it should be.
f) Does it make any difference if the outlier is near the end rather than in the middle of the time series?
# Change Jun in year 3 to compare an outlier in the middle
plastics3 <- plastics

plastics3[length(plastics2)-30] <- plastics[length(plastics)-30]+500
decomp3 <- decompose(plastics3, type="multiplicative")
sadjust3 <- seasadj(decomp3)

autoplot(sadjust3) + scale_y_continuous(labels=comma) +
  labs(title='Monthly Sales of Plastic Product "A"',
       subtitle = "Seasonally-adjusted (Middle Outlier)",
       y="Sales", x="Time")

  • As with the outlier at the end of the data, it shows in the seasonally-adjusted plot. So, it doesn’t seem to make any difference whether the outlier is in the middle or the end of the data.

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?

# Load the retail data
# A3349414R series ("Turnover ;  Victoria ;  Liquor retailing ;")
retail <- readxl::read_xlsx("retail.xlsx",skip=1)
myts <- ts(retail[,"A3349414R"], frequency = 12, start = c(1982,4))
# Initial plot of the data
autoplot(myts) +
  labs(title="Liquor Retailing Turnover",subtitle="Victoria") +
  xlab("Date") + ylab("Turnover")

myts.decomp <- myts %>% seas(x11="")
autoplot(myts.decomp)