a. Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle
Plastics shows a upward (positive) trend with what appears to be a annual seasonal pattern that can be describe as downward move in January, followed by an increasing moves through June/July and then followed by a downward move through January.
b. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
multiplicative_decomposition <- decompose(plastics, type = "multiplicative") autoplot(multiplicative_decomposition) + theme_fivethirtyeight()
c. Do the results support the graphical interpretation from part a?
Yes the results of the graphs support that the trend is increasing and that the timeseries has a seasonal component.
d. Compute and plot the seasonally adjusted data.
plastics %>% decompose(type="multiplicative") -> fit autoplot(plastics, series = "Data") + autolayer(seasadj(fit), series = "Seasonally Adjusted") + autolayer(trendcycle(multiplicative_decomposition), series="Trend") + labs(title = "Plastics", subtitle = 'With Seasonaly Adjusted Data') + theme_fivethirtyeight()
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?
outlier_plastics <- plastics outlier_plastics[40] <- outlier_plastics[40] + 500 outlier_plastics %>% decompose(type="multiplicative") -> outlier_fit autoplot(outlier_plastics, series = "Data") + autolayer(trendcycle(outlier_fit), series = "Trend") + autolayer(seasadj(outlier_fit), series = "Seasonally Adjusted") + labs(title = "Plastics", subtitle = 'With Seasonaly Adjusted Data and Outlier') + theme_fivethirtyeight()
Plastics with no Outlier
Plastics with Outlier
In the autoplot the outlier creates a spike in the data line as well as the seasonal line. When we compare the plastics decomposed plots with and without the outlier, it appears the remainder captures most of the outliers impact in such a way that the trend and seasonal plots of the with outlier and without outlier differ very little (The remainder seems to squelch the impact of the outlier in the trend and seasonal plots). The data plots and remainder plots seem to reflect the full impact of the outlier. (see above)
f. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
outlier_plastics <- plastics outlier_plastics[55] <- outlier_plastics[55] + 500 outlier_plastics %>% decompose(type="multiplicative") -> outlier_fit autoplot(outlier_plastics, series = "Data") + autolayer(trendcycle(outlier_fit), series = "Trend") + autolayer(seasadj(outlier_fit), series = "Seasonally Adjusted") + labs(title = "Plastics", subtitle = 'With Seasonaly Adjusted Data and end of series Outlier') + theme_fivethirtyeight()
Plastics with no Outlier
Plastics with Outlier towards end of series
Placing the outlier towards the end of the series seems to reduce the impact on the seasonal plot, as the seasonal plot with outlier looks almost identical to the seasonal plot without outlier. I am still able to see the impact of the outlier in the trend line plot.
- 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) myts <- ts(retaildata[,"A3349335T"], frequency=12, start=c(1982,4)) x11_df <- seas(myts, x11="") autoplot(x11_df) + ggtitle("X11 Decomposition of New South Wales Supermarket and grocery store Sales") + theme_fivethirtyeight()
Original Plot From Assignment 2
retaildata <- readxl::read_excel("retail.xlsx", skip=1) myts <- ts(retaildata[,"A3349335T"], frequency=12, start=c(1982,4)) myCaption <- BoxCox.lambda(myts) myts %>% as_tsibble() %>% mutate(BoxCox = BoxCox.lambda(value)) %>% autoplot() + labs(title = "New South Wales Supermarket and grocery store Sales", subtitle = str_c('Transformation parameter lambda: ', myCaption), caption= str_c('Data Source: A3349335T')) + theme_fivethirtyeight() + theme(plot.subtitle = element_text(color = "#008FD5"))
Yes, the x11 decomposition reveals numerous outliers. The spikes in the remainder segment clearly calls out outliers in several timeframes (1988-89, late 1994, 2001, 2012-2014). There also seems to be an increased number of outliers in the span of 2012-2014, as demonstrated in the residuals chart.