Chapter 6: Time Series Decomposition

library(tidyr)
library(dplyr)
library(knitr)
library(utils)
library(ggplot2)
library(readxl)
library(forecast)
library(fpp2)

Exercise 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)

seasonplot(plastics)

The plot shows both a seasonal fluctuation and a trend-cycle.

b. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
plastics %>% decompose(type="multiplicative") %>%
  autoplot() + xlab("Year") +
  ggtitle("Classical multiplicative decomposition
    of sales of product A for a plastics manufacturer")

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

The seasonal component can be seen to be essentially constant, and the trend component is linearly increasing, except for values near the last measurements (last year). So the decomposition results are in line with the graphical interpretation.

d. Compute and plot the seasonally adjusted data.
d = decompose(plastics, type="multiplicative")
s.adj = plastics / d$seasonal
plot(s.adj)

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?
plastics.orig = plastics

plastics[30] = plastics[30] + 500
d = decompose(plastics, type="multiplicative")
s.adj = plastics / d$seasonal
plot(s.adj)

The outlier increases the seasonally-adjusted value in the middle of the series.

f. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
plastics = plastics.orig
plastics[60] = plastics[60] + 500
d = decompose(plastics, type="multiplicative")
s.adj = plastics / d$seasonal
plot(s.adj)

When the outlier is near the end of the time series, the seasonally adjusted values also increase towards the end of the series. With the outlier in the middle of the series, the seasonally adjusted values increase in the middle as well. Thus, it appears that outliers are reflected in the seasonally adjusted values (and not in the seasonal component itself).

Exercise 6.3

Recall your \(retail\) time series data (from Exercise 3 in Section 2.10).

library(openxlsx)
file2 = "retail.xlsx"
retaildata <- read.xlsx(file2, sheet=1, startRow=2)
myts <- ts(retaildata[,"A3349873A"], frequency=12, start=c(1982,4))
autoplot(myts) +
    ggtitle("Australian retail data")

ggseasonplot(myts)

Decompose the series using $X11$. Does it reveal any outliers, or unusual features that you had not noticed previously?
library(seasonal)
d2 = seas(myts, x11 = "")
autoplot(d2) + 
    ggtitle("X11 decomposition of Australian retail data")

The decomposition plot shows a small variation in the seasonal component that is not apparent in the original timeseries plot. From the plot of the remainder, we see that there is an outlier around the middle of the plot (year 2000) and several towards the end. The remainder is not normally distributed.