The plastics
data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
autoplot(plastics, main = 'Monthly sales (in thousands) of product A for a plastics manufacturer')
There is a visible upward trend throughout 5 years. Additionally, there are seasonal fluctuations, sales start at the lowest level in the beginning of a year, peak mid-year and then slow down for the remainder of each year.
fit <- plastics %>% decompose(type = 'multiplicative')
autoplot(fit) + ggtitle('Classical multiplicative decomposition')
Yes, the results of decomposition support the assessment from part ‘a’. There few runs that suggest that some of the trend-cycle component got into remainder component because the trend-cycle has over-smoothed the data.
autoplot(plastics, series = 'Unadjusted') +
autolayer(seasadj(fit),series="Seasonally adjusted") + theme(legend.title=element_blank())
plastics_mid <- replace(plastics,30,350)
fit <- plastics_mid %>% decompose(type = 'multiplicative')
a <- autoplot(fit) + ggtitle('Multiplicative decomposition')
b <- autoplot(plastics_mid, series = 'Unadjusted') + ggtitle('With seasonal adjustment') +
autolayer(seasadj(fit),series="Seasonally adjusted") + theme(legend.position="bottom") + theme(legend.title=element_blank())
grid.arrange(a, b, nrow = 1)
plastics_end <- replace(plastics,57,350)
fit <- plastics_end %>% decompose(type = 'multiplicative')
a <- autoplot(fit) + ggtitle('Multiplicative decomposition')
b <- autoplot(plastics_end, series = 'Unadjusted') + ggtitle('With seasonal adjustment') +
autolayer(seasadj(fit),series="Seasonally adjusted") + theme(legend.position="bottom") + theme(legend.title=element_blank())
grid.arrange(a, b, nrow = 1)
It appears that adding an outlier towards the end of time series doesn’t change seasonally adjusted series by much other than creating a drop to indicate the outlier. Mid-series adjustment, however, seemed to keep some seasonality in as evident from the part ‘e’, seasonally adjusted series have a spike corresponding to each unadjusted series spike for all years but the one with an outlier, and hence affecting the whole series.
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?
download.file('https://otexts.com/fpp2/extrafiles/retail.xlsx','retail.xlsx')
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retaildata[,"A3349398A"],
frequency=12, start=c(1982,4))
fit <- myts %>% seas(x11='')
autoplot(fit) + ggtitle('X11 decomposition')
autoplot(myts, series='Data') +
autolayer(trendcycle(fit), series='Trend') +
autolayer(seasadj(fit),series="Seasonally adjusted") +
scale_colour_manual(values=c("gray","blue","red"),breaks=c("Data","Seasonally adjusted","Trend")) +
theme(legend.position="bottom") + theme(legend.title=element_blank())
Yes, few spikes in the remainder indicate the presence of potential outliers and we can see the data points that were not previously noticeable when plotted as part of time series.