library(fpp2)
## -- Attaching packages ------------------------------------------------------------------------------------------------------------------------------------------------------ fpp2 2.4 --
## v ggplot2 3.1.0 v fma 2.4
## v forecast 8.12 v expsmooth 2.3
##
The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
autoplot(plastics)
The plot shows there’s an overall upward trend over the five years. There appears to be a yearly seasonality.
plastics %>%
decompose(type="multiplicative") %>%
autoplot() +
ggtitle("Product A Sales")
Yes. The results support the graphical interpretation from part a. As you can see, seasonality is yearly and there’s an upward trend.
decompose_mult <- plastics %>%
decompose(type="multiplicative")
autoplot(plastics, series="Data") +
autolayer(seasadj(decompose_mult), series="Seasonally Adjusted") +
ggtitle("Product A Sales") +
ylab("Monthly Sales")
Seasonally adjusted plot shows the trend-cycle and remainder component of the data. The seasonal component of the data has been removed.
plastics2 <- plastics
plastics2[20] <- plastics2[20]+500
decompose_mult <- plastics2 %>%
decompose(type="multiplicative")
autoplot(plastics2, series='Data') +
autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')
I introduced an outlier on the 20th data point. And the outlier is visible in the seasonally adjusted plot. This is seen as a spike in the plot where the outlier was introduced.
plastics2 <- plastics
plastics2[5] <- plastics2[5]+500
decompose_mult <- plastics2 %>%
decompose(type="multiplicative")
autoplot(plastics2, series='Data') +
autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')
I introduced an outlier on the 5th data point. The effect is similar in that the location of the spike moved towards the beginning of the plot. But the overall trend/shape of the plot is the same.
plastics2 <- plastics
plastics2[50] <- plastics2[50]+500
decompose_mult <- plastics2 %>%
decompose(type="multiplicative")
autoplot(plastics2, series='Data') +
autolayer(seasadj(decompose_mult), series='Seasonally Adjusted')
I introduced an outlier on th 50th data point. The effect is similar in that the location of the spike moved towards the end of the plot. But the overall trend/shape of the plot is the same.
Based on my observation, the effect is similar whether the outlier is towards the beginning, middle, or end of the plot. The outlier is seen as a spike in the plot, but the overall shape of the plot remains the same.
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?
library(seasonal)
retaildata <- readxl::read_excel("retail.xlsx", skip=1)
#Turnover ; New South Wales ; Supermarket and grocery stores ;
myts <- ts(retaildata[,"A3349335T"],frequency=12, start=c(1982,4))
myts %>% seas(x11="") -> myts_x11
autoplot(myts_x11) +
ggtitle("X11 decomposition of Supermarket and Grocery Stores")
The plot shows seasonality and upward trend cycle. I don’t particularly notice any obvious outliers. It’s interesting that the magnitude of seasonal plot appears to slowly decrease, plateau for a bit and then slowly increase again.