library(fpp2)
The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
a.Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?
autoplot(plastics) +
ggtitle("Sales of product A for a plastics manufacturer") +
ylab("Monthly Sales of Product A") +
xlab("Year")
Inferece : The Time series shows a seasonality with a frequency of 1 year and an increasing trend.
plastics %>%
decompose(type="multiplicative") %>%
autoplot() +
ggtitle("Sales of Product A for a Plastics Manufacturer") +
xlab("Year")
Inference: The results of the multiplicative decomposition shows a yearly seasonal component with a frequency of 1 year as previously answered. There is an increasing trend from after the 1st year through five years and then the trend seems to buck down a bit.
d.Compute and plot the seasonally adjusted data.
multi_decom <- plastics %>%
decompose(type="multiplicative")
autoplot(plastics, series="Data") +
autolayer(seasadj(multi_decom), series="Seasonally Adjusted") +
ggtitle("Sales of Product A for a Plastics Manufacturer") +
ylab("Monthly Sales of Product A") +
xlab("Year")
Inference: The seasonally adjusted plot shows the monthly sales of product A with the seasonality removed. The upward trend and remainder make up the seasonally adjusted plot.
plst <- plastics
plst[20] <- plst[20]+500
multi_decom_spike <- plst %>%
decompose(type="multiplicative")
plst %>%
decompose(type="multiplicative") %>%
autoplot() +
ggtitle("Sales of Product A for a Plastics Manufacturer")
autoplot(plst, series="Data") +
autolayer(seasadj(multi_decom_spike), series="Seasonally Adjusted") +
ggtitle("Sales of Product A for a Plastics Manufacturer with Spike added ") +
ylab("Monthly Sales of Product A")
** The introduction of a spike to the data alters the seasonaly adjusted data and it does show the spike there and similarly in the multi decomposition, a minor spike is introduced in seasoanlity part of the chart.
plst <- plastics
plst[40] <- plst[40]+500
multi_decom_spike_end <- plst %>%
decompose(type="multiplicative")
plst %>%
decompose(type="multiplicative") %>%
autoplot() +
ggtitle("Sales of Product A for a Plastics Manufacturer")
autoplot(plst, series="Data") +
autolayer(seasadj(multi_decom_spike_end), series="Seasonally Adjusted") +
ggtitle("Sales of Product A for a Plastics Manufacturer with Spike added ") +
ylab("Monthly Sales of Product A")
inference : The introduction of spike to the end of the data shows similar spike in the seasonality data.. however on multi decompsition , the seasonality part of it does not show much variation. Not sure if the inference is correct.
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)
retail <- readxl::read_excel("retail.xlsx", skip=1)
myts <- ts(retail[,"A3349399C"],frequency=12, start=c(1982,4))
myts %>% seas(x11="") -> mytsX11
autoplot(mytsX11) +
ggtitle("X11 decomposition of Clothing Sales in New South Wales")
Inference : The X-11 decomposition shows a seasonal component with a frequency of 1 year. There is an increasing trend. Chart shows a couple spike in the data between 2000 and 2001. THe longer history of the data seems to take away the spike influence however on a shorter time series, it is kind of evident as above.