library(fpp2)
library(readxl)
library(seasonal)
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.
plastics %>% decompose(type="multiplicative") %>%
autoplot() + xlab("Time") +
ggtitle("Classical Multiplicative Decomposition of Monthly Sales of Product 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.
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.
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.
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.
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.