library(fpp2)
library(ggplot2)
library(seasonal)

Homework-3 Exercises

6.2 The plastics data set

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)

ggseasonplot(plastics)

  • The plots show that the data is highly seasonal and with a consistent positive trend. It also appears that the height of the seasonal trends appear to increase with time.

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

plastics %>% decompose(type="multiplicative") %>%
  autoplot()

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

  • Yes, the results of decomposition support the features of the data being highly seasonal and with almost linearly increasing trend.

d. Compute and plot the seasonally adjusted data.

plastics %>% decompose(type="multiplicative") -> fit
autoplot(plastics, series = "Data") +
  autolayer(seasadj(fit), series = "Seasonally Adjusted")

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?

oplastics <- plastics
oplastics[28] <- oplastics[28] + 500
oplastics %>% decompose(type="multiplicative") -> ofit
autoplot(oplastics, series = "Data") +
  autolayer(trendcycle(ofit), series = "Trend") +
  autolayer(seasadj(ofit), series = "Seasonally Adjusted")
## Warning: Removed 12 rows containing missing values (geom_path).

  • The effect of the outlier is a slight distortion in the trend’s straght line, but it has been mostly absorbed into the remainder component, as evident from the graph above. Therefore it is likely that the seasonal component hasn’t changed much because of the outlier. This conclusion is confimed by the decomposition plot below as well.
oplastics %>% decompose(type="multiplicative") %>%
  autoplot()

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

oplastics <- plastics
oplastics[57] <- oplastics[57] + 500

oplastics %>% decompose(type="multiplicative") -> ofit
autoplot(oplastics, series = "Data") +
  autolayer(trendcycle(ofit), series = "Trend") +
  autolayer(seasadj(ofit), series = "Seasonally Adjusted")
## Warning: Removed 12 rows containing missing values (geom_path).

oplastics %>% decompose(type="multiplicative") %>%
  autoplot()

  • My initial guess was that there would not be much difference, because there is no concept of “weight” distribution for near vs. far point contributions. Based on the graph there is less effect or rather much less of a distortion when an outlier is near the end. There is perhaps a slight jump in the trend line towards the end and almost no impact to the seasonality component. The remainder has not captured the outlier. This may be due to the drawback of the classical decomposition which does not include end-points.

6.3 Retail data

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?

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

myts %>% seas(x11="") -> fit
autoplot(fit) +
  ggtitle("X11 decomposition of Retail data")

  • There are no obvious outliers in the data itself and in the decomposition graphs except for a few instances in the remainder portion, which are not noticed by simply looking at the raw-data graph.