1. The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.
  1. 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
## Loading required package: fma
## Loading required package: expsmooth
autoplot(plastics)+ ggtitle("Product A Sales") + xlab("Year") + ylab("Sales")

This Time Plot shows very clearly that the data have upward trend and seasonal fluctuations peaking midway through the year.

  1. Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
data_decomp <- decompose(plastics, type = "multiplicative")
#  trend-cycle indices
data_decomp$trend
##         Jan       Feb       Mar       Apr       May       Jun       Jul
## 1        NA        NA        NA        NA        NA        NA  976.9583
## 2 1000.4583 1011.2083 1022.2917 1034.7083 1045.5417 1054.4167 1065.7917
## 3 1117.3750 1121.5417 1130.6667 1142.7083 1153.5833 1163.0000 1170.3750
## 4 1208.7083 1221.2917 1231.7083 1243.2917 1259.1250 1276.5833 1287.6250
## 5 1374.7917 1382.2083 1381.2500 1370.5833 1351.2500 1331.2500        NA
##         Aug       Sep       Oct       Nov       Dec
## 1  977.0417  977.0833  978.4167  982.7083  990.4167
## 2 1076.1250 1084.6250 1094.3750 1103.8750 1112.5417
## 3 1175.5000 1180.5417 1185.0000 1190.1667 1197.0833
## 4 1298.0417 1313.0000 1328.1667 1343.5833 1360.6250
## 5        NA        NA        NA        NA        NA
#  seasonal indices
data_decomp$seasonal
##         Jan       Feb       Mar       Apr       May       Jun       Jul
## 1 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
## 2 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
## 3 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
## 4 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
## 5 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
##         Aug       Sep       Oct       Nov       Dec
## 1 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
## 2 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
## 3 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
## 4 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
## 5 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
#  multiplicative decomposition (plot)
autoplot(data_decomp) + xlab("Year") +
  ggtitle("Multiplicative Decomposition Of Product A Sales")

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

Yes, the trend-cycle indices show a steady rise over the years. Seasonal indices confirm stable repeating fluctuations during the years with peaks in summer months.

  1. Compute and plot the seasonally adjusted data.
plot(plastics, col="black", main="Seasonally Adjusted Data Of Product A Sales")
lines(seasadj(data_decomp), col="red")

The resulting plot shows the seasonally adjusted data represented by a red line which includes trend-cycle and remainder components.

  1. 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?
t1 <- plastics
t1[25] = t1[25] + 500

t1_decomp <- decompose(t1, type="multiplicative")
t1_adj <- seasadj(t1_decomp)

plot1<-autoplot(t1_adj) + ggtitle("Seasonally Adjusted Data Of Product A Sales (with the outlier in the middle)")
plot1

  1. Does it make any difference if the outlier is near the end rather than in the middle of the time series?
t2 <- plastics
t2[50] <- t2[50] + 500

t2_decomp <- decompose(t2, type="multiplicative")
t2_adj <- seasadj(t2_decomp)
autoplot(t2_adj) + ggtitle("Seasonally Adjusted Data Of Product A Sales (with the outlier at the end)")

plot(seasadj(data_decomp), col="black", main="Seasonally Adjusted Data Of Product A Sales", ylim=c(0, 1800))
lines(seasadj(t1_decomp), col="red", ylim=c(0, 1800))
lines(seasadj(t2_decomp), col="green",ylim=c(0, 1800))

black line: seasonally adjusted data without outlier

red line: seasonally adjusted data with outlier at the middle

green line: seasonally adjusted data with outlier at the end