Week 4 - Decomposition - Homework

C. Rosemond 09.20.20

library(fpp2)
library(readxl)
library(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)

This time series describes monthly sales of product A for a plastics manufacturer. The series shows an upward trend over the course of the given five years, and it displays clear seasonality every 12 months. Notably, there are relative peaks during the summer months and relative troughs during the winter months.


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

plastics %>%  decompose(type="multiplicative") %>%
  autoplot() + xlab("Time") +
  ggtitle("Classical Multiplicative Decomposition of Monthly Sales of Product A")


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

A plot of the decomposed time series displays both the seasonal and trend-cycle components. The decomposed results support the graphical interpretation from part a. The upward trend is clear, though there is a slight downtick in early year 5. Likewise, the seasonal component reflects a fixed pattern in sales that repeats every 12 months.


d. Compute and plot the seasonally adjusted data.

plastics_seasadj <- plastics %>%  decompose(type="multiplicative") %>% seasadj()
autoplot(plastics_seasadj) + ggtitle("Monthly Sales of Product A - Seasonally-Adjusted")

Removing the seasonal component results in a seasonally adjusted time series that is, understandably, visually different with little apparent pattern. The general trend remains, though the downward tick in year 5--starting around month 5--is amplified.


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_outlier <- plastics
plastics_outlier[22] <- plastics_outlier[22] + 500 # adding 500 to 22nd observation
plastics_outlier %>%  decompose(type="multiplicative") %>% seasadj() %>% autoplot() + ggtitle("Outlier at Month 22")

Creating an outlier by adding 500 to an observation mostly affects the data itself rather than its seasonal component. Plotting the seasonally-adjusted data shows a substantial positive blip (~ 300) in the data due to the outlier. However, the blip does not equal the full addition of 500, suggesting that the seasonal component accounts for at least a portion of that addition.


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

plastics_outlier <- plastics
plastics_outlier[54] <- plastics_outlier[54] + 500 # adding 500 to 54th observation
plastics_outlier %>%  decompose(type="multiplicative") %>% seasadj() %>% autoplot() + ggtitle("Outlier at Month 54")

Adding an outlier towards the end of the seasonally-adjusted series--at month 54--simply shifts the positive blip along the series. Again, the the adjusted series does not reflect the full addition of 500.



6.3

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 <- read_excel("C:\\Users\\Charlie\\Documents\\CUNY_MSDS\\fall20\\624\\Week2\\retail.xlsx", skip=1)
myts <- ts(retaildata[,4], frequency=12, start=c(1982,4))
autoplot(myts) + ggtitle("Monthly Australian Retail Data - A3349338X")

The time series trends upward and shows monthly seasonality. Starting in late 1994, variation increases and continues to grow over time. The series drops substantially around the start of the year 2000.


myts %>% seas(x11="") %>% autoplot() + ggtitle("Monthly Australia Retail Data - A3349338X - X11 Decomposition")

An X11 decomposition pulls out the respective STR components of the retail time series. Before decomposition, there are not obvious outliers. Afterward, the remainder component suggests unusual positive blips in 1994, 1998, 2000, 2008, and 2010; there are also relatively unusual negative dips throughout the series. The seasonal component displays slight shifts in pattern as well as substantially greater variation over time; these patterns are more apparent after decomposition.