require(fpp2)
## Loading required package: fpp2
## Loading required package: ggplot2
## Loading required package: forecast
## Loading required package: fma
## Loading required package: expsmooth
require(seasonal)
## Loading required package: seasonal
plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.autoplot(plastics) +
ggtitle("Product A sales") +
xlab("Year") +
ylab("Sales (in thousands)")
There does seem to be a heavy seasonal fluctuation where sales spike midway through the year, then drop towards the end/beginning. There is also an upward trend happening as the years progress.
plastics %>% decompose(type = "multiplicative") %>%
autoplot() + xlab("Year") +
ggtitle("Multiplicative decomposition of product A sales")
Yes, the seasonal section shows a stable, repeating pattern as suspected from the original data, meanwhile the trend section shows a steady rise.
pla.adj <- seasadj(decompose(plastics, type = "multiplicative"))
autoplot(pla.adj) +
ggtitle("Product A sales seasonally adjusted") +
xlab("Year") +
ylab("Sales (in thousands)")
temp <- plastics
temp[15] <- temp[15] + 1000
temp.adj <- seasadj(decompose(temp, type = "multiplicative"))
autoplot(temp.adj) +
ggtitle("Product A sales seasonally adjust with outlier") +
xlab("Year") +
ylab("Sales (in thousands)")
The outlier creates a huge jump in the graph.
In theory it shouldn’t. The outlier should simply create a jump wherever it is seen, especially in the case of seasonally adjusted data. This should be easy to test, however.
t1 <- plastics
t2 <- plastics
t1[2] <- t1[2] + 1000
t2[55] <- t2[55] + 1000
t1.adj <- seasadj(decompose(t1, type = "multiplicative"))
t2.adj <- seasadj(decompose(t2, type = "multiplicative"))
autoplot(t1.adj) +
ggtitle("Outlier at beginning")
autoplot(t2.adj) +
ggtitle("Outlier at end")
Which is exactly what we see.
retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
retail <- ts(retaildata[, "A3349337W"], frequency = 12, start = c(1982, 4))
fit <- seas(retail, x11 = "")
autoplot(fit) +
ggtitle("X11 decomposition of retail data")
It’s interesting that the magnitude of the seasonal data decreases as the years go on, yet the trend continues upward. I’d guess that that seasonal swing was a lot stronger prior to 1990, although it’s hard to even see that in the regular plot of the data.