Chapter 6 - Time series decomposition



  1. 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?
  2. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
  3. Do the results support the graphical interpretation from part a?
  4. Compute and plot the seasonally adjusted data.
  5. 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?
  6. Does it make any difference if the outlier is near the end rather than in the middle of the time series?

autoplot(plastics)

multiplicative_decomposition <- decompose(plastics, type = "multiplicative")
autoplot(multiplicative_decomposition)

autoplot(plastics, series="Data") +
  autolayer(trendcycle(multiplicative_decomposition), series="Trend") +
  autolayer(seasadj(multiplicative_decomposition), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Monthly Sales in Thousands") +
  ggtitle("Plastic Product Sales") +
  scale_colour_manual(values=c("gray","blue","red"), breaks=c("Data","Seasonally Adjusted","Trend"))

outliered_plastics <- plastics
outliered_plastics[18] <- outliered_plastics[18] + 500
multiplicative_decomposition_new <- decompose(outliered_plastics, type = "multiplicative")

autoplot(outliered_plastics, series = "Data") +
  autolayer(trendcycle(multiplicative_decomposition_new), series = "Trend") +
  autolayer(seasadj(multiplicative_decomposition_new), series = "Seasonally Adjusted") +
  xlab("Year") + ylab("Monthly Sales in Thousands") +
  ggtitle("Plastic Product Sales") +
  scale_color_manual(values=c("gray", "blue", "red"), breaks=c("Data", "Seasonally Adjusted", "Trend"))

outliered_plastics[40] <- outliered_plastics[40] + 500
multiplicative_decomposition_new <- decompose(outliered_plastics, type = "multiplicative")

autoplot(outliered_plastics, series = "Data") +
  autolayer(trendcycle(multiplicative_decomposition_new), series = "Trend") +
  autolayer(seasadj(multiplicative_decomposition_new), series = "Seasonally Adjusted") +
  xlab("Year") + ylab("Monthly Sales in Thousands") +
  ggtitle("Plastic Product Sales") +
  scale_color_manual(values=c("gray", "blue", "red"), breaks=c("Data", "Seasonally Adjusted", "Trend"))



  1. 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?

## readxl works best with a newer version of the tibble package.
## You currently have tibble v1.4.2.
## Falling back to column name repair from tibble <= v1.4.2.
## Message displays once per session.

x11_retail <- seas(myts, x11 = "")
autoplot(x11_retail)