Exercise 6.2

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?

str(plastics)
##  Time-Series [1:60] from 1 to 5.92: 742 697 776 898 1030 ...
start(plastics)
## [1] 1 1
end(plastics)
## [1]  5 12
frequency(plastics)
## [1] 12
autoplot(plastics)

The plot suggest upward trend with strong seasonality which peaks for few months at the 2nd half of the year but dips before the year ends.

b. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.

plastics %>% decompose(type="multiplicative") %>%
  autoplot() + xlab("Year") +
  ggtitle("Classical multiplicative decomposition
    of Sales of plastic product")

c. Do the results support the graphical interpretation from part a? Yes the decomposed graphs confirms trend and seasonality of the data

d. Compute and plot the seasonally adjusted data.

fit <- decompose(plastics)
autoplot(plastics, series="Data") +
  autolayer(trendcycle(fit), series="Trend") +
  autolayer(seasadj(fit), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Monthly Sales of product A") +
  ggtitle("Sales of Plastic Product") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 rows containing missing values (geom_path).

e. Change one observation to be an outlier (e.g., add 500 to one observation), and recompute the seasonally adjusted data. What is the effect of the outlier?

plastics_mid_outlier <- plastics
plastics_mid_outlier[27] <- plastics_mid_outlier[27] + 500

fit_mid <- decompose(plastics_mid_outlier)

autoplot(seasadj(fit), series="Seasonally Adjusted") +
  autolayer(trendcycle(fit_mid), series="Trend") +
  autolayer(seasadj(fit_mid), series="Seasonally Adjusted - Mid Outlier") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Seasonally Adjusted",
                      "Seasonally Adjusted - Mid Outlier","Trend"))
## Warning: Removed 12 rows containing missing values (geom_path).

Interestingly, with outlier being in the middle, the trend seemed to be less smooth, and the seasonality appeared to have dips in the body of the series where previously they were not as much pronounced.

f. Does it make any difference if the outlier is near the end rather than in the middle of the time series?

plastics_end_outlier <- plastics
plastics_end_outlier[55] <- plastics_end_outlier[55] + 500

fit_end <- decompose(plastics_end_outlier)

autoplot(seasadj(fit), series="Seasonally Adjusted") +
  autolayer(trendcycle(fit_end), series="Trend") +
  autolayer(seasadj(fit_mid), series="Seasonally Adjusted - Mid Outlier") +
  autolayer(seasadj(fit_end), series="Seasonally Adjusted - End Outlier") +
  scale_colour_manual(values=c("gray","blue","green","red"),
             breaks=c("Seasonally Adjusted",
                      "Seasonally Adjusted - Mid Outlier",
                      "Seasonally Adjusted - End Outlier",
                      "Trend"))
## Warning: Removed 12 rows containing missing values (geom_path).

Yes it appears that the end outlier did not create as much variance in seasonality as when the outlier was in the middle of the series. Furthermore, the overall trend appeared smoother compared to previous with middle outlier.

Exercise 6.3

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?

retaildata <- readxl::read_excel("retail.xlsx", skip=1)

#Chose col B Turnover New South Wales Supermarket and grocery stores
myts <- ts(retaildata[,"A3349335T"], 
  frequency=12, start=c(1982,4))


myts %>% seas(x11="") -> fit
autoplot(fit) +
  ggtitle("X11 decomposition of Grocery Stores turnover in New South Wales")

fit %>% seasonal() %>% ggsubseriesplot() + ylab("Seasonal")

The X11 decomposition confirms the earlier observation of trend and seasonality. The subseriesplot highlighted the Dec high season peak. In addition, since the trend-cycle, seasonality, remainder components breaks them apart, there’s clearer observation that the seasonality peaks decreases with upward trend.