library(tidyverse)
library(fpp2)
autoplot(plastics)
There appears to be annual seasonality and an positive trend.
plastics %>%
decompose(type="multiplicative") %>%
autoplot()
Generally, the decomposed time series data agrees with the initial analysis but there are additional details that are made very obvious by the decomposition. The trend starts to decline in year 5. This could not have been seen without decomposition.
plastics %>%
decompose(type="multiplicative") %>%
seasadj() %>%
autoplot()
plastics2 <- plastics
plastics2[35] <- plastics2[35] + 500
plastics2 %>%
decompose(type="multiplicative") %>%
seasadj() %>%
autoplot(series="Outlier") +
autolayer(seasadj(decompose(plastics, type="multiplicative")), series="Original")
The outlier throws off the rest of the seasonally adjusted plot. The calculations used expect this outlier to contribute to the seasonal component so annually, each 11th month, there is an increased variance from the original seasonally adjusted plot.
plastics3 <- plastics
plastics4 <- plastics
plastics5 <- plastics
plastics3[6] <- plastics[6] + 500
plastics4[50] <- plastics[50] + 500
plastics5[20] <- plastics[20] + 500
autoplot(seasadj(decompose(plastics, type="multiplicative")), series="Original") +
autolayer(seasadj(decompose(plastics2, type="multiplicative")), series="Outlier at 35") +
autolayer(seasadj(decompose(plastics3, type="multiplicative")), series="Outlier at 6") +
autolayer(seasadj(decompose(plastics4, type="multiplicative")), series="Outlier at 50") +
autolayer(seasadj(decompose(plastics5, type="multiplicative")), series="Outlier at 20")
This is so cool. It seems that for multiplicative decomposition, outliers affect the entire plot if they are after the first season. The magnitude of the effect outliers have on the rest of the plot seems similar no matter which subsequent season it’s in.
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349873A"], frequency=12, start=c(1982,4))
myts %>%
seasonal::seas(x11="") %>%
autoplot()
It’s cool the see the variations in seasonal activity. It’s cool to see a more robust trendline. One thing that stands out that I didn’t notice is the negative remainder in 2011. I can see the dip on the original data after analyzing the decompisition.