require(fpp2)
## Loading required package: fpp2
## Loading required package: ggplot2
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
require(seasonal)
## Loading required package: seasonal

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("Product A sales") +
  xlab("Year") +
  ylab("Sales (in thousands)")

There does seem to be a heavy seasonal fluctuation where sales spike midway through the year, then drop towards the end/beginning. There is also an upward trend happening as the years progress.

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

plastics %>% decompose(type = "multiplicative") %>%
  autoplot() + xlab("Year") +
  ggtitle("Multiplicative decomposition of product A sales")

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

Yes, the seasonal section shows a stable, repeating pattern as suspected from the original data, meanwhile the trend section shows a steady rise.

d. Compute and plot the seasonally adjusted data

pla.adj <- seasadj(decompose(plastics, type = "multiplicative"))
autoplot(pla.adj) +
  ggtitle("Product A sales seasonally adjusted") + 
  xlab("Year") +
  ylab("Sales (in thousands)")

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?

temp <- plastics
temp[15] <- temp[15] + 1000
temp.adj <- seasadj(decompose(temp, type = "multiplicative"))
autoplot(temp.adj) +
  ggtitle("Product A sales seasonally adjust with outlier") +
  xlab("Year") +
  ylab("Sales (in thousands)")

The outlier creates a huge jump in the graph.

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

In theory it shouldn’t. The outlier should simply create a jump wherever it is seen, especially in the case of seasonally adjusted data. This should be easy to test, however.

t1 <- plastics
t2 <- plastics

t1[2] <- t1[2] + 1000
t2[55] <- t2[55] + 1000

t1.adj <- seasadj(decompose(t1, type = "multiplicative"))
t2.adj <- seasadj(decompose(t2, type = "multiplicative"))

autoplot(t1.adj) +
  ggtitle("Outlier at beginning")

autoplot(t2.adj) +
  ggtitle("Outlier at end")

Which is exactly what we see.

6.3 Recall your retail time series data (from Exercise 3 in Section 2.10). Decompose this series using X11. Does it reveal any outliers or unusual features you had not noticed previously?

retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
retail <- ts(retaildata[, "A3349337W"], frequency = 12, start = c(1982, 4))

fit <- seas(retail, x11 = "")
autoplot(fit) +
  ggtitle("X11 decomposition of retail data")

It’s interesting that the magnitude of the seasonal data decreases as the years go on, yet the trend continues upward. I’d guess that that seasonal swing was a lot stronger prior to 1990, although it’s hard to even see that in the regular plot of the data.