Chapter 6 - Time series decomposition
The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?
Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
Do the results support the graphical interpretation from part a?
Compute and plot the seasonally adjusted data.
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?
Does it make any difference if the outlier is near the end rather than in the middle of the time series?
autoplot(plastics)

- The plot of the data shows that there are seasonal fluctuations and upward trend.
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"))

- The outlier affects on the trend lightly and on the seasonally adjusted data highly
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"))

- Trend decrease at near end outlier
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.

- The plot shows that there are trend and seasonality in the data.
x11_retail <- seas(myts, x11 = "")
autoplot(x11_retail)

- Unexpected outliers seen when decomposing the series using X11, especially between 2000 and 2001
- When trend increased, the seasonality effect decreased