Data 624 - Week 3 Assignment

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?

library(fpp2)
## Loading required package: ggplot2
## Loading required package: forecast
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## Loading required package: fma
## Loading required package: expsmooth
#help(plastics)

autoplot(plastics) + 
  xlab('Year') + 
  ylab('Sales(thousands)') + 
  ggtitle('Sales of plastic product')

Observation

Clearly there is a upward trend, seasonality and cyclic.

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 plastic product Sales")

c. Do the results support the graphical interpretation from part a?

Yes, After decomposing, There is still an upward trend, seasonality.In the residual plot, i see some randomness towards at the end.

d.Compute and plot the seasonally adjusted data.

#install.packages('seasonal')
library(seasonal)


# use the same classical multiplicative decompisition 
plastics %>% decompose(type="multiplicative")-> fit


autoplot(plastics, series="Data") +
  autolayer(trendcycle(fit), series="Trend") +
  autolayer(seasadj(fit), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Sales(Thousand)") +
  ggtitle("Plastic Sales") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 row(s) 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?

Lets add an outlier(in- fact a big value than normal) to somewhere middle of the obseration

plastics_cp1 <- plastics

plastics_cp1[32] <- 5000


plastics_cp1 %>% decompose(type="multiplicative")-> fit


autoplot(plastics_cp1, series="Data") +
  autolayer(trendcycle(fit), series="Trend") +
  autolayer(seasadj(fit), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Sales(Thousand)") +
  ggtitle("Plastic Sales") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

Observation

The trend and seasonal component has caused a spike at center to accommodate the outlier.

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

Lets add the same outlier towards the end of the series. We see that the same spike is observed towards the end of the series. Recall that classical decomposition methods are not robust to outliers, may need alternate methods to get better representation for trend-cycle and seasonal pattern.

plastics_cp2 <- plastics

plastics_cp2[50] <- 5000
plastics_cp2 %>% decompose(type="multiplicative")-> fit


autoplot(plastics_cp2, series="Data") +
  autolayer(trendcycle(fit), series="Trend") +
  autolayer(seasadj(fit), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Sales(Thousand)") +
  ggtitle("Plastic Sales") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

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?

Lets load the retail time series data and plot the original time-series

retaildata <- readxl::read_excel('C:\\Users\\charls.joseph\\Documents\\Cuny\\Data624\\week1\\retail.xlsx', skip=1)
myts <- ts(retaildata[,"A3349397X"],
  frequency=12, start=c(1982,4))

autoplot(myts) +
  xlab('Year') +
  ylab("Turn Over")

Lets decompose the retail timeseries using X11 method

myts %>% seas(x11="") -> fit

autoplot(fit) +
  ggtitle("X11 decomposition of retail Turn Over")

Observation

I had previously noted an upward trend and clear seasonality from the original plot. But after decomposing and looking at the reminder, I see there is an outlier somewhere in 2001. I havent noticed that before.