Libraries

library(kableExtra)
library(tidyverse)
library(ggplot2)
library(dplyr)
library(TSstudio)
library(RColorBrewer)
library(GGally)
library(fpp2)
library(seasonal)
library(grid)
library(gridExtra)
#library(ggpubr)

Forecasting: Principles & Practice

Section 6.9 - Exercise 2

The plastics data set consists of the monthly sales (in thousands) of product A for a plastics manufacturer for five years.

DataSet: plastics

Description: Monthly sales of product A for a plastics manufacturer.

plastics 
##    Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
## 1  742  697  776  898 1030 1107 1165 1216 1208 1131  971  783
## 2  741  700  774  932 1099 1223 1290 1349 1341 1296 1066  901
## 3  896  793  885 1055 1204 1326 1303 1436 1473 1453 1170 1023
## 4  951  861  938 1109 1274 1422 1486 1555 1604 1600 1403 1209
## 5 1030 1032 1126 1285 1468 1637 1611 1608 1528 1420 1119 1013
# Converting into a Data Frame
plastics_df <- ts_reshape(plastics,type="long")
colnames(plastics_df) <- c("YearNo","MonthNo","SalesQty")

plastics_df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
YearNo MonthNo SalesQty
1 1 742
1 2 697
1 3 776
1 4 898
1 5 1030
1 6 1107
1 7 1165
1 8 1216
1 9 1208
1 10 1131
1 11 971
1 12 783
2 1 741
2 2 700
2 3 774
2 4 932
2 5 1099
2 6 1223
2 7 1290
2 8 1349
2 9 1341
2 10 1296
2 11 1066
2 12 901
3 1 896
3 2 793
3 3 885
3 4 1055
3 5 1204
3 6 1326
3 7 1303
3 8 1436
3 9 1473
3 10 1453
3 11 1170
3 12 1023
4 1 951
4 2 861
4 3 938
4 4 1109
4 5 1274
4 6 1422
4 7 1486
4 8 1555
4 9 1604
4 10 1600
4 11 1403
4 12 1209
5 1 1030
5 2 1032
5 3 1126
5 4 1285
5 5 1468
5 6 1637
5 7 1611
5 8 1608
5 9 1528
5 10 1420
5 11 1119
5 12 1013
  1. Plot the time series of sales of product A. Can you identify seasonal fluctuations and/or a trend-cycle?

Time Series Plot:

autoplot(plastics,ylab="Sold Quantity (in Thousands)",xlab="Year") + ggtitle("Annual Sales of Product A")

From the Time Series plot above, seasonal fluctuations are crealy noticable along with a positive trend reflecting gradual increase in sales from year 1 to year 5. To further verify the seasonal fluctiations, I have also created seasonal and a subseries plots.

Seasonal & Subseries Plots:

seasonplot <- ggseasonplot(plastics,year.labels=TRUE,year.labels.left = TRUE) +
  ylab("Sold Quantity (in Thousands)") +
  ggtitle("Seasonal plot:Annual Sales of Product A")

subseriesplot <- ggsubseriesplot(plastics) +
  ylab("Sold Quantity (in Thousands)") +
  ggtitle("Seasonal subseries plot: Annual Sales of Product A")

grid.arrange(seasonplot,subseriesplot, ncol=2) 

Seasonal fluctuations are further verified based on above plots.

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

Estimating value of Seasonal Period m:

For getting a sense of the seasonal period m for the plastics data set, I have used the ACF and lagplot as below -

title <- "ACF plot:Annual Sales of Product A"
acfPlot <- ggAcf(plastics) + ggtitle(title)

title <- "Lag plot:Annual Sales of Product A"
lagPlot <- gglagplot(plastics) + ggtitle(title)

grid.arrange(acfPlot,lagPlot, ncol=2) 

From the above two plots, it can be safely deduced that here seasonal period, m = 12.

Estimation of Trend-Cycle Component \({ \overset { \^ }{ { T }_{ t } } }\):

In the classical method of time series decomposition, a moving average method is used to estimate the Trend-Cycle component. Since here, m is an even no., the Trend-Cycle component \({ \overset { \^ }{ { T }_{ t } } }\) can be calculated using 2 X 12-MA as below -

ma2x12 <- ma(plastics, order=12, centre=TRUE)

ma2x12
##         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

I have merged the trend-cycle components in the data frame -

TrendCycleDF <- ts_reshape(ma2x12, type="long")
colnames(TrendCycleDF) <- c("YearNo","MonthNo","TrendCycle")

plastics_df %>% inner_join(TrendCycleDF) -> plastics_df
## Joining, by = c("YearNo", "MonthNo")
plastics_df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
YearNo MonthNo SalesQty TrendCycle
1 1 742 NA
1 2 697 NA
1 3 776 NA
1 4 898 NA
1 5 1030 NA
1 6 1107 NA
1 7 1165 976.9583
1 8 1216 977.0417
1 9 1208 977.0833
1 10 1131 978.4167
1 11 971 982.7083
1 12 783 990.4167
2 1 741 1000.4583
2 2 700 1011.2083
2 3 774 1022.2917
2 4 932 1034.7083
2 5 1099 1045.5417
2 6 1223 1054.4167
2 7 1290 1065.7917
2 8 1349 1076.1250
2 9 1341 1084.6250
2 10 1296 1094.3750
2 11 1066 1103.8750
2 12 901 1112.5417
3 1 896 1117.3750
3 2 793 1121.5417
3 3 885 1130.6667
3 4 1055 1142.7083
3 5 1204 1153.5833
3 6 1326 1163.0000
3 7 1303 1170.3750
3 8 1436 1175.5000
3 9 1473 1180.5417
3 10 1453 1185.0000
3 11 1170 1190.1667
3 12 1023 1197.0833
4 1 951 1208.7083
4 2 861 1221.2917
4 3 938 1231.7083
4 4 1109 1243.2917
4 5 1274 1259.1250
4 6 1422 1276.5833
4 7 1486 1287.6250
4 8 1555 1298.0417
4 9 1604 1313.0000
4 10 1600 1328.1667
4 11 1403 1343.5833
4 12 1209 1360.6250
5 1 1030 1374.7917
5 2 1032 1382.2083
5 3 1126 1381.2500
5 4 1285 1370.5833
5 5 1468 1351.2500
5 6 1637 1331.2500
5 7 1611 NA
5 8 1608 NA
5 9 1528 NA
5 10 1420 NA
5 11 1119 NA
5 12 1013 NA

From the table above, it can be observed that the trend-cycle componenet for first and last 6 months' observations are missing. This is a known limitation of classical decomposition method.

To see what the trend-cycle estimate looks like, we plot it along with the original data -

autoplot(plastics, series="Data") +
  autolayer(ma(plastics, order=12, centre=TRUE), series="2X12-MA") +
  xlab("Year") + ylab("Sold Quantity (in Thousands)") +
  ggtitle("Annual Sales of Product A") +
  scale_colour_manual(values=c("Data"="grey50","2X12-MA"="red"),
                      breaks=c("Data","2X12-MA"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

Estimation of Seasonal Component \({ \overset { \^ }{ { S }_{ t } } }\):

Step 1: Calculating the de-trended series: \(\frac { { y }_{ t } }{ { \overset { \^ }{ { T }_{ t } } } }\) as below -

plastics_df %>% mutate(DeTrendedSeries=SalesQty/TrendCycle) -> plastics_df

plastics_df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
YearNo MonthNo SalesQty TrendCycle DeTrendedSeries
1 1 742 NA NA
1 2 697 NA NA
1 3 776 NA NA
1 4 898 NA NA
1 5 1030 NA NA
1 6 1107 NA NA
1 7 1165 976.9583 1.1924766
1 8 1216 977.0417 1.2445733
1 9 1208 977.0833 1.2363326
1 10 1131 978.4167 1.1559492
1 11 971 982.7083 0.9880856
1 12 783 990.4167 0.7905764
2 1 741 1000.4583 0.7406605
2 2 700 1011.2083 0.6922411
2 3 774 1022.2917 0.7571225
2 4 932 1034.7083 0.9007369
2 5 1099 1045.5417 1.0511298
2 6 1223 1054.4167 1.1598830
2 7 1290 1065.7917 1.2103679
2 8 1349 1076.1250 1.2535718
2 9 1341 1084.6250 1.2363720
2 10 1296 1094.3750 1.1842376
2 11 1066 1103.8750 0.9656890
2 12 901 1112.5417 0.8098573
3 1 896 1117.3750 0.8018794
3 2 793 1121.5417 0.7070625
3 3 885 1130.6667 0.7827241
3 4 1055 1142.7083 0.9232452
3 5 1204 1153.5833 1.0437044
3 6 1326 1163.0000 1.1401548
3 7 1303 1170.3750 1.1133184
3 8 1436 1175.5000 1.2216078
3 9 1473 1180.5417 1.2477323
3 10 1453 1185.0000 1.2261603
3 11 1170 1190.1667 0.9830556
3 12 1023 1197.0833 0.8545771
4 1 951 1208.7083 0.7867903
4 2 861 1221.2917 0.7049913
4 3 938 1231.7083 0.7615439
4 4 1109 1243.2917 0.8919870
4 5 1274 1259.1250 1.0118138
4 6 1422 1276.5833 1.1139108
4 7 1486 1287.6250 1.1540627
4 8 1555 1298.0417 1.1979585
4 9 1604 1313.0000 1.2216299
4 10 1600 1328.1667 1.2046681
4 11 1403 1343.5833 1.0442225
4 12 1209 1360.6250 0.8885622
5 1 1030 1374.7917 0.7492044
5 2 1032 1382.2083 0.7466313
5 3 1126 1381.2500 0.8152036
5 4 1285 1370.5833 0.9375570
5 5 1468 1351.2500 1.0864015
5 6 1637 1331.2500 1.2296714
5 7 1611 NA NA
5 8 1608 NA NA
5 9 1528 NA NA
5 10 1420 NA NA
5 11 1119 NA NA
5 12 1013 NA NA

Step 2: To estimate the seasonal component for each month, simple average of the detrended values can be derived for that month. The seasonal component is obtained by stringing together these monthly indexes, and then replicating the sequence for each year of data. This gives us \({ \overset { \^ }{ { S }_{ t } } }\) -

plastics_df %>% group_by(MonthNo) %>% summarise(SeasonalIndex = mean(DeTrendedSeries,na.rm = TRUE)) -> SeasonalSummary
## `summarise()` ungrouping output (override with `.groups` argument)
SeasonalSummary
MonthNo SeasonalIndex
1 0.7696337
2 0.7127315
3 0.7791485
4 0.9133815
5 1.0482624
6 1.1609050
7 1.1675564
8 1.2294279
9 1.2355167
10 1.1927538
11 0.9952632
12 0.8358933
plastics_df %>% inner_join(SeasonalSummary) -> plastics_df
## Joining, by = "MonthNo"
## Deriving the Remainder Component
plastics_df %>% mutate(RemainderValue = SalesQty/(TrendCycle*SeasonalIndex)) -> plastics_df

plastics_df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
YearNo MonthNo SalesQty TrendCycle DeTrendedSeries SeasonalIndex RemainderValue
1 1 742 NA NA 0.7696337 NA
1 2 697 NA NA 0.7127315 NA
1 3 776 NA NA 0.7791485 NA
1 4 898 NA NA 0.9133815 NA
1 5 1030 NA NA 1.0482624 NA
1 6 1107 NA NA 1.1609050 NA
1 7 1165 976.9583 1.1924766 1.1675564 1.0213439
1 8 1216 977.0417 1.2445733 1.2294279 1.0123191
1 9 1208 977.0833 1.2363326 1.2355167 1.0006604
1 10 1131 978.4167 1.1559492 1.1927538 0.9691432
1 11 971 982.7083 0.9880856 0.9952632 0.9927883
1 12 783 990.4167 0.7905764 0.8358933 0.9457863
2 1 741 1000.4583 0.7406605 0.7696337 0.9623546
2 2 700 1011.2083 0.6922411 0.7127315 0.9712509
2 3 774 1022.2917 0.7571225 0.7791485 0.9717306
2 4 932 1034.7083 0.9007369 0.9133815 0.9861563
2 5 1099 1045.5417 1.0511298 1.0482624 1.0027354
2 6 1223 1054.4167 1.1598830 1.1609050 0.9991197
2 7 1290 1065.7917 1.2103679 1.1675564 1.0366676
2 8 1349 1076.1250 1.2535718 1.2294279 1.0196384
2 9 1341 1084.6250 1.2363720 1.2355167 1.0006923
2 10 1296 1094.3750 1.1842376 1.1927538 0.9928600
2 11 1066 1103.8750 0.9656890 0.9952632 0.9702851
2 12 901 1112.5417 0.8098573 0.8358933 0.9688526
3 1 896 1117.3750 0.8018794 0.7696337 1.0418975
3 2 793 1121.5417 0.7070625 0.7127315 0.9920460
3 3 885 1130.6667 0.7827241 0.7791485 1.0045890
3 4 1055 1142.7083 0.9232452 0.9133815 1.0107991
3 5 1204 1153.5833 1.0437044 1.0482624 0.9956519
3 6 1326 1163.0000 1.1401548 1.1609050 0.9821258
3 7 1303 1170.3750 1.1133184 1.1675564 0.9535457
3 8 1436 1175.5000 1.2216078 1.2294279 0.9936393
3 9 1473 1180.5417 1.2477323 1.2355167 1.0098871
3 10 1453 1185.0000 1.2261603 1.1927538 1.0280079
3 11 1170 1190.1667 0.9830556 0.9952632 0.9877343
3 12 1023 1197.0833 0.8545771 0.8358933 1.0223520
4 1 951 1208.7083 0.7867903 0.7696337 1.0222920
4 2 861 1221.2917 0.7049913 0.7127315 0.9891400
4 3 938 1231.7083 0.7615439 0.7791485 0.9774053
4 4 1109 1243.2917 0.8919870 0.9133815 0.9765766
4 5 1274 1259.1250 1.0118138 1.0482624 0.9652295
4 6 1422 1276.5833 1.1139108 1.1609050 0.9595194
4 7 1486 1287.6250 1.1540627 1.1675564 0.9884428
4 8 1555 1298.0417 1.1979585 1.2294279 0.9744032
4 9 1604 1313.0000 1.2216299 1.2355167 0.9887603
4 10 1600 1328.1667 1.2046681 1.1927538 1.0099889
4 11 1403 1343.5833 1.0442225 0.9952632 1.0491923
4 12 1209 1360.6250 0.8885622 0.8358933 1.0630092
5 1 1030 1374.7917 0.7492044 0.7696337 0.9734559
5 2 1032 1382.2083 0.7466313 0.7127315 1.0475631
5 3 1126 1381.2500 0.8152036 0.7791485 1.0462750
5 4 1285 1370.5833 0.9375570 0.9133815 1.0264681
5 5 1468 1351.2500 1.0864015 1.0482624 1.0363832
5 6 1637 1331.2500 1.2296714 1.1609050 1.0592351
5 7 1611 NA NA 1.1675564 NA
5 8 1608 NA NA 1.2294279 NA
5 9 1528 NA NA 1.2355167 NA
5 10 1420 NA NA 1.1927538 NA
5 11 1119 NA NA 0.9952632 NA
5 12 1013 NA NA 0.8358933 NA

Applying decompose() method for multiplicative decomposition:

Finally, applying multiplication decomposition method on plastics dataset, we get below output -

plastics %>% decompose(type="multiplicative") -> plasticsDecomposed
plasticsDecomposed
## $x
##    Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
## 1  742  697  776  898 1030 1107 1165 1216 1208 1131  971  783
## 2  741  700  774  932 1099 1223 1290 1349 1341 1296 1066  901
## 3  896  793  885 1055 1204 1326 1303 1436 1473 1453 1170 1023
## 4  951  861  938 1109 1274 1422 1486 1555 1604 1600 1403 1209
## 5 1030 1032 1126 1285 1468 1637 1611 1608 1528 1420 1119 1013
## 
## $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
## 
## $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
## 
## $random
##         Jan       Feb       Mar       Apr       May       Jun       Jul
## 1        NA        NA        NA        NA        NA        NA 1.0247887
## 2 0.9656005 0.9745267 0.9750081 0.9894824 1.0061175 1.0024895 1.0401641
## 3 1.0454117 0.9953920 1.0079773 1.0142083 0.9990100 0.9854384 0.9567618
## 4 1.0257400 0.9924762 0.9807020 0.9798704 0.9684851 0.9627557 0.9917766
## 5 0.9767392 1.0510964 1.0498039 1.0299302 1.0398787 1.0628077        NA
##         Aug       Sep       Oct       Nov       Dec
## 1 1.0157335 1.0040354 0.9724119 0.9961368 0.9489762
## 2 1.0230774 1.0040674 0.9962088 0.9735577 0.9721203
## 3 0.9969907 1.0132932 1.0314752 0.9910657 1.0258002
## 4 0.9776897 0.9920952 1.0133954 1.0527311 1.0665946
## 5        NA        NA        NA        NA        NA
## 
## $figure
##  [1] 0.7670466 0.7103357 0.7765294 0.9103112 1.0447386 1.1570026 1.1636317
##  [8] 1.2252952 1.2313635 1.1887444 0.9919176 0.8330834
## 
## $type
## [1] "multiplicative"
## 
## attr(,"class")
## [1] "decomposed.ts"

Comparing the manually calculated Trend-Cycle and Seasonal Indices values with the output of the decompose() method, I can see slight mismatch in the Seasonal Indices values.

Plot of decompose() output:

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

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

The results in the above analysis support the interpretations of part a. The increasing positive trend in sales is clearly visible from Trend-Cycle plot. The seasonal fluctuations can be observed through compensations made by the remainder values computed in the decomposition method.

  1. Compute and plot the seasonally adjusted data.

Seasonally Adjusted Series Computation

The seasonally adjusted timeseries data can be computed using the seasadj() function of the decomposed.ts output object of the classical multiplicatove decompose() function call derived in part b.

plasticsDecomposed %>% seasadj() %>% ts_reshape(type="long") -> plasticsSeasAdj
colnames(plasticsSeasAdj) <- c("YearNo","MonthNo","SeasonalAdjSales")
plastics_df %>% inner_join(plasticsSeasAdj) -> plastics_df
## Joining, by = c("YearNo", "MonthNo")
plastics_df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
YearNo MonthNo SalesQty TrendCycle DeTrendedSeries SeasonalIndex RemainderValue SeasonalAdjSales
1 1 742 NA NA 0.7696337 NA 967.3468
1 2 697 NA NA 0.7127315 NA 981.2262
1 3 776 NA NA 0.7791485 NA 999.3182
1 4 898 NA NA 0.9133815 NA 986.4758
1 5 1030 NA NA 1.0482624 NA 985.8925
1 6 1107 NA NA 1.1609050 NA 956.7826
1 7 1165 976.9583 1.1924766 1.1675564 1.0213439 1001.1759
1 8 1216 977.0417 1.2445733 1.2294279 1.0123191 992.4139
1 9 1208 977.0833 1.2363326 1.2355167 1.0006604 981.0263
1 10 1131 978.4167 1.1559492 1.1927538 0.9691432 951.4241
1 11 971 982.7083 0.9880856 0.9952632 0.9927883 978.9119
1 12 783 990.4167 0.7905764 0.8358933 0.9457863 939.8819
2 1 741 1000.4583 0.7406605 0.7696337 0.9623546 966.0431
2 2 700 1011.2083 0.6922411 0.7127315 0.9712509 985.4495
2 3 774 1022.2917 0.7571225 0.7791485 0.9717306 996.7427
2 4 932 1034.7083 0.9007369 0.9133815 0.9861563 1023.8257
2 5 1099 1045.5417 1.0511298 1.0482624 1.0027354 1051.9377
2 6 1223 1054.4167 1.1598830 1.1609050 0.9991197 1057.0417
2 7 1290 1065.7917 1.2103679 1.1675564 1.0366676 1108.5982
2 8 1349 1076.1250 1.2535718 1.2294279 1.0196384 1100.9592
2 9 1341 1084.6250 1.2363720 1.2355167 1.0006923 1089.0366
2 10 1296 1094.3750 1.1842376 1.1927538 0.9928600 1090.2260
2 11 1066 1103.8750 0.9656890 0.9952632 0.9702851 1074.6860
2 12 901 1112.5417 0.8098573 0.8358933 0.9688526 1081.5244
3 1 896 1117.3750 0.8018794 0.7696337 1.0418975 1168.1168
3 2 793 1121.5417 0.7070625 0.7127315 0.9920460 1116.3736
3 3 885 1130.6667 0.7827241 0.7791485 1.0045890 1139.6864
3 4 1055 1142.7083 0.9232452 0.9133815 1.0107991 1158.9443
3 5 1204 1153.5833 1.0437044 1.0482624 0.9956519 1152.4413
3 6 1326 1163.0000 1.1401548 1.1609050 0.9821258 1146.0648
3 7 1303 1170.3750 1.1133184 1.1675564 0.9535457 1119.7701
3 8 1436 1175.5000 1.2216078 1.2294279 0.9936393 1171.9625
3 9 1473 1180.5417 1.2477323 1.2355167 1.0098871 1196.2349
3 10 1453 1185.0000 1.2261603 1.1927538 1.0280079 1222.2981
3 11 1170 1190.1667 0.9830556 0.9952632 0.9877343 1179.5334
3 12 1023 1197.0833 0.8545771 0.8358933 1.0223520 1227.9683
4 1 951 1208.7083 0.7867903 0.7696337 1.0222920 1239.8204
4 2 861 1221.2917 0.7049913 0.7127315 0.9891400 1212.1029
4 3 938 1231.7083 0.7615439 0.7791485 0.9774053 1207.9388
4 4 1109 1243.2917 0.8919870 0.9133815 0.9765766 1218.2647
4 5 1274 1259.1250 1.0118138 1.0482624 0.9652295 1219.4437
4 6 1422 1276.5833 1.1139108 1.1609050 0.9595194 1229.0378
4 7 1486 1287.6250 1.1540627 1.1675564 0.9884428 1277.0364
4 8 1555 1298.0417 1.1979585 1.2294279 0.9744032 1269.0820
4 9 1604 1313.0000 1.2216299 1.2355167 0.9887603 1302.6210
4 10 1600 1328.1667 1.2046681 1.1927538 1.0099889 1345.9580
4 11 1403 1343.5833 1.0442225 0.9952632 1.0491923 1414.4319
4 12 1209 1360.6250 0.8885622 0.8358933 1.0630092 1451.2352
5 1 1030 1374.7917 0.7492044 0.7696337 0.9734559 1342.8129
5 2 1032 1382.2083 0.7466313 0.7127315 1.0475631 1452.8342
5 3 1126 1381.2500 0.8152036 0.7791485 1.0462750 1450.0416
5 4 1285 1370.5833 0.9375570 0.9133815 1.0264681 1411.6051
5 5 1468 1351.2500 1.0864015 1.0482624 1.0363832 1405.1361
5 6 1637 1331.2500 1.2296714 1.1609050 1.0592351 1414.8628
5 7 1611 NA NA 1.1675564 NA 1384.4587
5 8 1608 NA NA 1.2294279 NA 1312.3369
5 9 1528 NA NA 1.2355167 NA 1240.9008
5 10 1420 NA NA 1.1927538 NA 1194.5377
5 11 1119 NA NA 0.9952632 NA 1128.1178
5 12 1013 NA NA 0.8358933 NA 1215.9647

Seasonally Adjusted Series Plot

autoplot(plastics, series="Data") +
  autolayer(trendcycle(plasticsDecomposed), series="Trend") +
  autolayer(seasadj(plasticsDecomposed), series="Seasonally Adjusted") +
  xlab("Year") + ylab("Sold Quantity (in Thousands)") +
  ggtitle("Annual Sales of Product A") +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

  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?

Impact of Outlier on Seasonally Adjusted Series

I have added an outlier (added 500) in the middle of the time series (Year=3 and Month = 'Jul') to gauge the impact.

# Create a copy of the original plastics timeseries
plastics_new <- plastics

# Index for the Year 3 and Month of Jul is 31; Created outlier by adding 500
plastics_new[31] <- plastics[31] + 500

# Calculate Seasonally adjusted Series with the outlier

plastics_new %>% decompose(type="multiplicative") -> plasticsOutlierMiddle


#### Plot of decompose() output:
plasticsOutlierMiddle %>%
  autoplot() + xlab("Year") +
  ggtitle("Annual Sales of Product A with Outlier (in the Middle)")

# Plot including the outlier
autoplot(plastics_new, series="Data") +
  autolayer(trendcycle(plasticsOutlierMiddle), series="Trend") +
  autolayer(seasadj(plasticsDecomposed), series="Seasonally Adjusted") +
  autolayer(seasadj(plasticsOutlierMiddle), series="Seasonally Adjusted w/ Outlier (Middle)") +
  xlab("Year") + ylab("Sold Quantity (in Thousands)") +
  ggtitle("Annual Sales of Product A with Outlier (in the Middle)") +
  scale_colour_manual(values=c("gray","blue","dark green","red"),
             breaks=c("Data","Seasonally Adjusted","Seasonally Adjusted w/ Outlier (Middle)","Trend"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

From the plot above, it is clear that adding the outlier in the middle, has impacted the trend and seasonally adjusted data in the middle of the time series mostly as expected. But it can also be observed that the outlier impacted the front and tail of the seasonally adjusted data especially near the peaks of the original data set.

Impact of Outlier on Strength of Trend and Seasonality:

Considering the definition of decomposition as: \({ y }_{ t }={ T }_{ t }+{ S }_{ t }+{ R }_{ t }\),

The strength of trend can be defined as: \({ F }_{ T }=max(0,1-\frac { Var({ R }_{ t }) }{ (Var({ T }_{ t })+Var({ R }_{ t })) } )\)

And, the strength of Seasonality can be defined as: \({ F }_{ S }=max(0,1-\frac { Var({ R }_{ t }) }{ (Var({ S }_{ t })+Var({ R }_{ t })) } )\)

# Strength of Trend in Orginal decomposed data:
Ft <- max(0,1-(var(remainder(plasticsDecomposed), na.rm = TRUE)/(var(trendcycle(plasticsDecomposed), na.rm = TRUE)+var(remainder(plasticsDecomposed), na.rm = TRUE))))

# Strength of Trend in decomposed data including outlier (Added in the Middle of the Time series:
Ft1 <- max(0,1-(var(remainder(plasticsOutlierMiddle), na.rm = TRUE)/(var(trendcycle(plasticsOutlierMiddle), na.rm = TRUE)+var(remainder(plasticsOutlierMiddle), na.rm = TRUE))))

cat("Strength of Trend (Original):",Ft,"\n")
## Strength of Trend (Original): 0.9999999
cat("Strength of Trend (Outlier in the Middle):",Ft1,"\n")
## Strength of Trend (Outlier in the Middle): 0.9999999
# Strength of Seasonality in Orginal decomposed data:
Fs <- max(0,1-(var(remainder(plasticsDecomposed), na.rm = TRUE)/(var(seasonal(plasticsDecomposed), na.rm = TRUE)+var(remainder(plasticsDecomposed), na.rm = TRUE))))

# Strength of Trend in decomposed data including outlier (Added in the Middle of the Time series:
Fs1 <- max(0,1-(var(remainder(plasticsOutlierMiddle), na.rm = TRUE)/(var(seasonal(plasticsOutlierMiddle), na.rm = TRUE)+var(remainder(plasticsOutlierMiddle), na.rm = TRUE))))

cat("Strength of Seasonality (Original):",Fs,"\n")
## Strength of Seasonality (Original): 0.9763389
cat("Strength of Seasonality (Outlier in the Middle):",Fs1,"\n")
## Strength of Seasonality (Outlier in the Middle): 0.9544627

From the above analysis, it can be concluded that the due to introduction of outlier in the middle of the time series, the strength of trend was not impacted. But the strength of seasonality got reduced. f) Does it make any difference if the outlier is near the end rather than in the middle of the time series?

Impact of Outlier (at the end) on Seasonally Adjusted Seriesc

I have added an outlier (added 500) towards the end of the time series (Year=5 and Month = 'Oct') to gauge the impact.

# Create a copy of the original plastics timeseries
plastics_new1 <- plastics

# Index for the Year 5 and Month of Oct is 58; Created outlier by adding 500
plastics_new1[58] <- plastics[58] + 500

# Calculate Seasonally adjusted Series with the outlier

plastics_new1 %>% decompose(type="multiplicative") -> plasticsOutlierEnd

#### Plot of decompose() output:
plasticsOutlierEnd %>%
  autoplot() + xlab("Year") +
  ggtitle("Annual Sales of Product A with Outlier (towards the End)")

# Plot including the outlier
autoplot(plastics_new1, series="Data") +
  autolayer(trendcycle(plasticsOutlierEnd), series="Trend") +
  autolayer(seasadj(plasticsDecomposed), series="Seasonally Adjusted") +
  autolayer(seasadj(plasticsOutlierMiddle), series="Seasonally Adjusted w/ Outlier (Middle)") +
  autolayer(seasadj(plasticsOutlierEnd), series="Seasonally Adjusted w/ Outlier (End)") +
  xlab("Year") + ylab("Sold Quantity (in Thousands)") +
  ggtitle("Annual Sales of Product A with Outlier (Towards the end)") +
  scale_colour_manual(values=c("gray","blue","dark green","brown","red"),
             breaks=c("Data","Seasonally Adjusted","Seasonally Adjusted w/ Outlier (Middle)","Seasonally Adjusted w/ Outlier (End)","Trend"))
## Warning: Removed 12 row(s) containing missing values (geom_path).

From the plot above, it can be observed that the BROWN line ('Seasonally Adjusted w/ Outlier(end)') follows the BLUE line ('Original Seasonally Adjusted data') pretty closely for most part of the time series other than the spike towards the tail end where the outlier (Year 5, Oct) has been planted. Whereas the GREEN line ('Seasonally Adjusted w/ Outlier (Middle)') shows variation from BLUE line more or less throughout the time series with major variation in the middle (Year 3, July). So having the outlier towards the tail end definitely shows LESS impact in overall fitting of the time series rather than in the middle.

Impact of Outlier on Strength of Trend and Seasonality:

# Strength of Trend in decomposed data including outlier (Added towards the end of the Time series:
Ft2 <- max(0,1-(var(remainder(plasticsOutlierEnd), na.rm = TRUE)/(var(trendcycle(plasticsOutlierEnd), na.rm = TRUE)+var(remainder(plasticsOutlierEnd), na.rm = TRUE))))

cat("Strength of Trend (Outlier towards the end):",Ft2,"\n")
## Strength of Trend (Outlier towards the end): 1
# Strength of Trend in decomposed data including outlier (Added towards the end of the Time series:
Fs2 <- max(0,1-(var(remainder(plasticsOutlierEnd), na.rm = TRUE)/(var(seasonal(plasticsOutlierEnd), na.rm = TRUE)+var(remainder(plasticsOutlierEnd), na.rm = TRUE))))

cat("Strength of Seasonality (Outlier towards the end):",Fs2,"\n")
## Strength of Seasonality (Outlier towards the end): 0.9793166

From the above, it looks like the strength of Trend and Seasonality have improved from original data set due to introduction of outlier towards the end of the time series.

Section 6.9 - Exercise 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?

DataSet: Retail

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

head(retaildata, 20) %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Series ID A3349335T A3349627V A3349338X A3349398A A3349468W A3349336V A3349337W A3349397X A3349399C A3349874C A3349871W A3349790V A3349556W A3349791W A3349401C A3349873A A3349872X A3349709X A3349792X A3349789K A3349555V A3349565X A3349414R A3349799R A3349642T A3349413L A3349564W A3349416V A3349643V A3349483V A3349722T A3349727C A3349641R A3349639C A3349415T A3349349F A3349563V A3349350R A3349640L A3349566A A3349417W A3349352V A3349882C A3349561R A3349883F A3349721R A3349478A A3349637X A3349479C A3349797K A3349477X A3349719C A3349884J A3349562T A3349348C A3349480L A3349476W A3349881A A3349410F A3349481R A3349718A A3349411J A3349638A A3349654A A3349499L A3349902A A3349432V A3349656F A3349361W A3349501L A3349503T A3349360V A3349903C A3349905J A3349658K A3349575C A3349428C A3349500K A3349577J A3349433W A3349576F A3349574A A3349816F A3349815C A3349744F A3349823C A3349508C A3349742A A3349661X A3349660W A3349909T A3349824F A3349507A A3349580W A3349825J A3349434X A3349822A A3349821X A3349581X A3349908R A3349743C A3349910A A3349435A A3349365F A3349746K A3349370X A3349754K A3349670A A3349764R A3349916R A3349589T A3349590A A3349765T A3349371A A3349588R A3349763L A3349372C A3349442X A3349591C A3349671C A3349669T A3349521W A3349443A A3349835L A3349520V A3349841J A3349925T A3349450X A3349679W A3349527K A3349526J A3349598V A3349766V A3349600V A3349680F A3349378T A3349767W A3349451A A3349924R A3349843L A3349844R A3349376L A3349599W A3349377R A3349779F A3349379V A3349842K A3349532C A3349931L A3349605F A3349688X A3349456L A3349774V A3349848X A3349457R A3349851L A3349604C A3349608L A3349609R A3349773T A3349852R A3349775W A3349776X A3349607K A3349849A A3349850K A3349606J A3349932R A3349862V A3349462J A3349463K A3349334R A3349863W A3349781T A3349861T A3349626T A3349617R A3349546T A3349787F A3349333L A3349860R A3349464L A3349389X A3349461F A3349788J A3349547V A3349388W A3349870V A3349396W
1982-04-01 303.1 41.7 63.9 408.7 65.8 91.8 53.6 211.3 94.0 32.7 126.7 178.3 50.4 22.2 43.0 62.4 178.0 61.8 85.4 147.2 1250.2 257.9 17.3 34.9 310.2 58.2 55.8 59.1 173.1 93.6 26.3 119.9 104.2 42.2 15.6 31.6 34.4 123.7 36.4 48.7 85.1 916.2 139.3 NA NA 161.8 31.8 46.6 13.3 91.6 28.9 13.9 42.8 67.5 18.4 11.1 22.0 25.8 77.3 18.7 26.7 45.4 486.3 83.5 6.0 11.3 100.8 15.2 16.0 8.6 39.7 19.1 6.6 25.7 48.9 8.1 6.1 7.2 12.9 34.2 14.3 15.8 30.1 279.4 96.6 12.3 13.1 122.0 19.2 22.5 8.6 50.4 21.4 7.4 28.8 36.5 9.7 6.5 14.6 11.3 42.1 8.0 10.4 18.4 298.3 26.0 NA NA 28.4 6.1 5.1 2.4 13.6 6.7 1.9 8.7 NA 2.9 1.8 4.0 NA NA 1.9 3.5 5.4 79.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.7 1.2 1.6 15.5 2.7 4.4 2.6 9.7 3.7 2.2 5.9 10.3 2.3 1.1 2.5 2.2 8.1 4.4 3.2 7.6 57.1 933.4 79.6 149.6 1162.6 200.3 243.4 148.6 592.3 268.5 91.4 359.9 460.1 135.1 64.9 125.6 153.5 479.1 146.3 196.1 342.4 3396.4
1982-05-01 297.8 43.1 64.0 404.9 65.8 102.6 55.4 223.8 105.7 35.6 141.3 202.8 49.9 23.1 45.3 63.1 181.5 60.8 84.8 145.6 1300.0 257.4 18.1 34.6 310.1 62.0 58.4 59.2 179.5 95.3 27.1 122.5 110.2 42.1 15.8 31.5 34.4 123.9 36.2 48.9 85.1 931.2 136.0 NA NA 158.7 32.8 49.6 12.7 95.0 30.6 14.7 45.3 69.7 17.7 11.7 21.9 25.9 77.2 19.5 27.3 46.8 492.8 80.6 5.4 11.1 97.1 17.2 19.0 9.5 45.7 21.6 7.0 28.6 52.2 7.5 6.5 7.5 13.0 34.4 14.2 15.8 30.0 288.0 96.4 11.8 13.4 121.6 21.9 27.8 8.2 57.9 24.1 8.0 32.1 43.7 11.0 7.2 15.2 11.6 45.0 8.0 10.3 18.3 318.5 25.4 NA NA 27.7 6.3 4.7 2.5 13.4 7.4 1.9 9.3 NA 2.9 1.9 4.0 NA NA 2.0 3.5 5.5 78.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.1 1.4 1.6 15.1 3.0 4.9 3.3 11.1 3.8 2.1 5.9 10.6 2.5 1.0 2.5 2.0 8.0 3.4 3.3 6.7 57.3 920.5 80.8 149.7 1150.9 210.3 268.3 151.0 629.6 289.8 96.8 386.6 502.6 134.9 67.7 128.7 154.8 486.1 145.5 196.6 342.1 3497.9
1982-06-01 298.0 40.3 62.7 401.0 62.3 105.0 48.4 215.7 95.1 32.5 127.6 176.3 48.0 22.8 43.7 59.6 174.1 58.7 80.7 139.4 1234.2 261.2 18.1 34.6 313.9 53.8 53.7 59.8 167.3 85.2 24.3 109.6 96.7 38.5 15.2 29.6 33.5 116.8 35.7 47.1 82.8 887.0 143.5 NA NA 166.6 34.9 51.4 12.9 99.2 30.5 14.5 45.1 60.7 17.7 11.5 22.7 25.9 77.7 18.6 26.2 44.8 494.1 82.3 5.2 11.2 98.7 17.4 18.1 8.4 43.9 18.3 6.0 24.3 48.9 6.7 6.1 7.5 12.5 32.7 13.4 15.3 28.7 277.2 95.6 11.3 13.5 120.4 19.9 26.7 7.9 54.4 21.4 7.0 28.5 38.0 10.7 6.6 14.5 10.9 42.5 7.3 10.4 17.7 301.5 25.3 NA NA 27.7 6.4 5.2 2.1 13.7 6.7 1.8 8.6 NA 2.9 1.9 3.9 NA NA 2.0 3.1 5.1 77.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.5 1.3 1.7 15.5 2.5 4.8 2.7 9.9 3.2 2.0 5.1 9.9 2.3 1.0 2.5 2.0 7.8 3.6 3.5 7.1 55.3 933.6 77.3 149.0 1160.0 198.7 266.1 142.6 607.4 261.9 88.6 350.5 443.8 128.2 65.5 125.0 148.8 467.5 140.2 188.5 328.7 3357.8
1982-07-01 307.9 40.9 65.6 414.4 68.2 106.0 52.1 226.3 95.3 33.5 128.8 172.6 48.6 23.2 46.5 61.9 180.2 60.3 82.4 142.7 1265.0 266.1 18.9 35.2 320.2 57.9 56.9 59.8 174.5 91.6 25.6 117.2 104.6 38.9 15.2 35.2 33.4 122.7 34.6 47.5 82.1 921.3 150.2 NA NA 172.9 34.6 50.9 13.9 99.4 27.9 15.2 43.1 67.9 18.4 13.1 24.3 28.7 84.4 22.6 25.2 47.8 515.6 88.2 5.6 12.1 105.9 18.7 20.3 10.3 49.3 18.6 6.4 25.0 48.3 7.8 6.6 7.9 13.9 36.2 14.5 17.0 31.4 296.1 103.3 12.1 13.8 129.2 19.3 28.2 8.7 56.2 21.8 7.2 29.0 42.0 9.0 7.0 14.6 11.4 42.0 7.8 10.3 18.1 316.4 27.8 NA NA 30.3 5.9 5.2 2.7 13.7 7.1 1.8 8.9 NA 3.1 1.8 4.4 NA NA 1.9 3.6 5.5 82.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.2 1.4 1.6 16.1 2.8 5.1 2.4 10.2 3.4 2.1 5.4 8.8 2.6 1.1 2.6 2.0 8.3 4.0 3.5 7.5 56.3 972.6 80.4 153.5 1206.4 208.7 273.5 150.1 632.4 267.2 92.1 359.3 459.1 129.9 68.5 136.6 156.1 491.1 146.5 192.0 338.5 3486.8
1982-08-01 299.2 42.1 62.6 403.8 66.0 96.9 54.2 217.1 82.8 29.4 112.3 169.6 51.3 21.4 44.8 60.7 178.1 56.1 80.7 136.8 1217.6 247.2 19.0 33.8 300.1 59.2 56.7 62.2 178.1 85.2 23.5 108.7 92.5 39.5 14.5 34.7 33.2 122.0 32.5 49.3 81.8 883.2 144.0 NA NA 165.9 32.9 51.6 12.8 97.3 27.4 14.1 41.5 66.5 17.8 13.0 23.6 27.7 82.1 22.6 25.6 48.2 501.4 82.3 5.7 11.7 99.7 18.6 19.6 10.6 48.9 17.1 6.0 23.1 49.4 7.9 6.3 8.3 13.7 36.1 13.6 17.5 31.1 288.4 96.6 12.0 13.3 121.9 19.6 27.4 7.9 55.0 18.7 6.6 25.3 38.5 9.1 6.8 15.3 10.9 42.1 7.6 10.1 17.7 300.5 26.6 NA NA 29.0 5.7 4.8 2.9 13.4 5.8 1.7 7.5 NA 3.1 1.8 4.2 NA NA 1.9 3.6 5.5 78.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.7 1.6 1.6 15.8 2.8 4.6 2.7 10.1 3.1 2.0 5.0 8.8 2.6 0.9 2.8 2.0 8.4 3.6 3.7 7.3 55.4 923.5 81.6 147.3 1152.5 206.2 262.7 153.7 622.6 241.5 83.7 325.2 438.4 133.0 65.2 134.7 152.8 485.7 138.8 192.7 331.5 3355.9
1982-09-01 305.4 42.0 64.4 411.8 62.3 97.5 53.6 213.4 89.4 32.2 121.6 181.4 49.6 21.8 43.9 61.2 176.5 58.1 82.1 140.2 1244.9 262.4 18.4 35.4 316.2 57.1 58.9 63.6 179.6 89.5 24.3 113.8 98.3 41.7 15.1 34.2 34.5 125.5 33.9 50.7 84.6 917.9 146.9 NA NA 169.5 33.7 49.6 14.5 97.9 29.1 15.5 44.5 73.4 18.8 13.0 21.8 29.0 82.6 23.2 26.7 49.8 517.7 84.2 5.8 12.0 102.0 18.8 19.9 11.5 50.2 18.2 6.4 24.6 48.5 7.8 6.4 7.8 14.1 36.0 13.9 17.8 31.7 293.0 101.4 12.3 13.4 127.1 19.9 27.0 8.7 55.6 19.5 7.4 26.9 40.2 10.0 7.1 15.1 11.7 43.9 8.2 10.3 18.5 312.3 27.1 NA NA 29.6 5.3 4.8 2.6 12.8 5.8 1.7 7.5 NA 3.2 1.8 4.0 NA NA 1.9 3.8 5.7 79.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.9 1.4 1.8 16.0 2.6 4.3 3.1 10.0 3.4 2.2 5.6 9.2 2.6 1.0 2.8 2.2 8.6 4.2 3.9 8.1 57.5 955.9 81.4 151.8 1189.1 200.9 263.1 157.9 622.0 256.2 90.1 346.3 465.1 135.5 66.8 130.4 157.2 489.9 144.3 197.6 341.9 3454.3
1982-10-01 318.0 46.1 66.0 430.1 66.2 99.3 58.0 223.5 83.3 31.9 115.2 173.9 51.6 21.0 45.6 62.1 180.3 53.9 87.3 141.2 1264.2 285.4 20.9 38.0 344.3 66.9 59.6 64.1 190.5 93.0 25.8 118.7 102.8 46.2 16.3 35.9 36.7 135.2 37.7 54.1 91.7 983.3 143.7 NA NA 166.2 31.7 49.1 13.1 93.8 33.4 15.2 48.6 68.3 20.2 12.0 19.3 27.0 78.5 20.8 28.1 48.8 504.2 88.9 6.6 12.7 108.2 18.7 19.7 10.8 49.3 20.7 7.4 28.1 46.1 7.6 7.4 8.4 15.0 38.4 17.2 20.6 37.8 307.9 107.0 14.2 14.1 135.4 18.0 25.5 10.2 53.6 20.8 8.3 29.1 37.4 7.7 7.5 15.0 12.6 42.8 9.3 11.0 20.3 318.7 27.0 NA NA 29.5 5.5 4.2 2.6 12.3 5.3 1.6 7.0 NA 2.9 1.8 4.2 NA NA 2.0 3.9 5.9 78.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.5 1.5 1.7 16.6 3.7 4.7 3.5 11.9 3.4 2.3 5.8 9.7 2.7 1.2 2.6 2.5 9.0 4.8 4.0 8.9 61.9 999.3 90.8 157.3 1247.4 211.9 263.3 162.6 637.8 261.3 92.9 354.2 452.7 140.6 67.7 132.0 160.6 500.9 146.6 211.9 358.4 3551.5
1982-11-01 334.4 46.5 65.3 446.2 68.9 107.8 67.2 243.9 99.3 35.0 134.3 206.6 55.8 23.5 45.3 68.3 192.9 61.2 87.4 148.7 1372.6 291.9 22.4 38.2 352.5 78.1 63.2 82.5 223.8 107.9 29.0 136.9 114.6 43.5 17.5 38.0 40.7 139.7 40.3 57.3 97.7 1065.2 152.7 NA NA 175.4 33.8 53.2 14.9 101.9 35.5 15.9 51.4 73.4 21.5 13.2 19.2 29.7 83.6 22.7 27.6 50.4 536.0 87.0 6.5 12.2 105.7 21.0 22.7 13.1 56.8 23.6 8.0 31.6 58.5 8.8 7.8 8.8 15.8 41.2 17.3 20.9 38.2 332.1 108.7 14.2 13.8 136.7 19.0 27.4 13.2 59.6 23.8 8.8 32.6 42.4 8.4 7.9 15.7 13.9 45.9 9.6 11.1 20.8 337.9 28.0 NA NA 30.6 6.0 5.3 3.2 14.5 7.1 1.9 9.0 NA 3.1 2.0 4.7 NA NA 2.0 3.9 5.9 86.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.1 1.5 1.7 17.2 3.9 5.1 4.6 13.6 3.6 2.6 6.2 11.3 3.0 1.3 3.1 2.9 10.3 5.4 4.3 9.6 68.3 1031.9 92.3 156.5 1280.7 232.2 285.9 199.0 717.2 302.4 101.5 403.9 522.9 145.7 73.6 135.7 176.1 531.1 159.3 215.4 374.7 3830.5
1982-12-01 389.6 53.8 77.9 521.3 90.8 155.5 146.3 392.6 142.9 51.7 194.6 346.6 69.9 31.4 55.0 104.0 260.3 75.7 97.2 172.9 1888.3 334.6 29.7 43.9 408.2 87.5 90.3 143.0 320.8 148.2 39.8 188.0 208.5 57.2 21.5 56.5 57.3 192.5 45.2 64.1 109.3 1427.3 172.8 NA NA 198.0 42.6 79.0 29.4 151.0 48.8 22.1 70.9 127.9 30.9 16.2 23.8 41.5 112.4 24.5 31.1 55.7 715.9 99.1 8.6 14.5 122.1 23.8 30.3 25.4 79.6 33.4 11.7 45.1 88.9 12.9 10.5 11.1 23.1 57.6 22.8 24.8 47.6 440.9 128.5 16.2 16.0 160.7 23.0 37.6 26.6 87.2 34.8 13.1 47.9 71.9 11.8 11.0 19.6 21.5 63.9 13.4 12.4 25.7 457.4 32.7 NA NA 35.7 7.7 7.9 6.0 21.7 11.1 2.6 13.8 NA 4.6 2.5 5.8 NA NA 2.4 4.3 6.7 118.6 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 16.5 1.6 1.9 20.0 4.2 8.0 7.4 19.7 4.7 3.5 8.2 18.5 4.9 1.8 3.9 4.1 14.6 6.9 4.3 11.2 92.2 1190.4 111.0 182.3 1483.7 281.2 410.7 385.0 1077.0 426.1 145.2 571.4 889.3 194.0 95.8 176.7 258.7 725.2 192.6 240.5 433.1 5179.7
1983-01-01 311.4 43.8 65.1 420.3 58.0 95.1 66.6 219.7 78.5 31.4 109.8 135.3 50.1 20.7 47.4 63.9 182.1 54.2 93.0 147.2 1214.5 270.7 22.9 36.0 329.6 58.8 55.5 64.3 178.6 81.6 25.0 106.6 81.5 43.7 15.6 34.1 35.8 129.3 36.9 57.7 94.6 920.3 146.9 NA NA 169.3 28.8 50.1 14.1 92.9 29.7 14.9 44.6 64.0 22.8 12.0 17.7 27.8 80.4 20.5 30.7 51.2 502.4 82.7 7.1 12.5 102.3 19.7 18.8 9.2 47.7 20.0 6.4 26.4 43.5 8.0 6.7 8.1 13.9 36.6 15.3 24.2 39.5 295.9 94.6 15.7 12.1 122.3 16.6 25.8 9.6 52.0 18.8 7.2 26.0 35.6 7.4 6.7 14.3 11.4 39.8 8.0 11.6 19.6 295.4 26.8 NA NA 29.3 4.7 4.7 2.6 12.0 5.3 1.5 6.8 NA 2.9 1.7 3.9 NA NA 1.9 3.6 5.5 75.2 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.0 1.0 1.6 14.6 3.0 4.3 3.3 10.6 2.7 1.9 4.6 7.4 2.5 1.0 2.5 2.1 8.1 3.8 3.9 7.7 53.0 959.3 91.7 151.9 1202.8 190.7 255.4 169.9 615.9 237.7 88.8 326.5 379.2 138.6 64.9 128.5 159.3 491.4 141.8 226.9 368.6 3384.5
1983-02-01 327.2 39.3 62.3 428.8 63.7 105.1 59.2 228.0 72.9 29.4 102.3 144.2 64.7 22.1 44.0 64.8 195.5 56.7 85.1 141.8 1240.6 278.4 20.8 35.4 334.6 59.7 60.2 64.6 184.5 73.5 23.4 96.9 86.6 44.3 16.3 34.0 36.4 130.9 38.0 50.2 88.2 921.7 149.3 NA NA 170.5 26.2 47.5 12.3 86.0 25.2 12.6 37.9 53.5 20.2 11.5 17.0 25.8 74.5 19.7 27.9 47.6 470.0 85.3 6.4 11.7 103.5 18.9 19.8 8.5 47.2 17.3 5.9 23.2 39.7 8.9 6.4 7.1 13.0 35.4 13.9 21.2 35.1 284.1 100.6 13.3 12.3 126.2 16.7 24.9 9.6 51.1 18.0 7.0 25.0 33.2 7.4 6.6 13.2 11.2 38.4 7.9 10.7 18.6 292.6 26.9 NA NA 29.3 5.0 4.5 2.4 11.9 5.6 1.7 7.3 NA 3.2 1.9 3.8 NA NA 2.0 3.3 5.3 76.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 12.8 1.1 1.6 15.5 3.3 4.4 2.6 10.3 2.7 1.9 4.6 8.0 3.0 1.0 2.5 2.1 8.6 4.2 3.9 8.2 55.1 995.5 82.0 146.7 1224.2 194.8 267.5 159.4 621.7 216.4 82.3 298.7 378.0 152.8 66.4 122.1 157.9 499.1 143.7 204.4 348.1 3369.8
1983-03-01 350.9 43.4 65.7 460.0 66.0 124.1 67.3 257.5 93.3 34.2 127.5 180.5 63.1 24.9 47.7 70.0 205.7 60.9 83.7 144.6 1375.7 303.8 23.5 39.1 366.4 71.6 67.6 73.9 213.0 100.6 28.2 128.8 108.0 48.3 16.8 36.7 39.1 140.9 37.0 55.0 92.0 1049.2 162.4 NA NA 185.8 30.1 58.6 16.6 105.3 31.1 15.2 46.3 64.4 20.9 13.3 18.9 30.4 83.4 21.8 28.8 50.5 535.7 95.9 6.9 14.0 116.8 22.9 24.1 9.9 56.8 23.5 7.6 31.2 54.4 9.8 7.7 7.8 15.3 40.5 16.2 24.6 40.8 340.5 107.6 15.4 13.7 136.7 18.0 28.2 10.1 56.3 19.7 7.5 27.2 37.6 7.3 7.3 14.8 12.2 41.6 8.7 11.6 20.3 319.6 29.8 NA NA 32.6 6.0 5.7 3.0 14.7 6.5 1.9 8.5 NA 3.5 2.1 4.2 NA NA 2.3 3.4 5.7 89.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.8 1.1 1.8 16.7 3.6 5.3 3.1 12.0 3.8 2.5 6.3 10.6 3.1 1.1 2.6 2.2 9.1 4.0 4.4 8.5 63.1 1080.8 91.4 160.3 1332.4 219.8 315.1 184.2 719.1 279.7 97.5 377.2 472.1 157.3 73.7 133.2 174.4 538.7 151.9 213.9 365.8 3805.3
1983-04-01 323.4 43.7 61.9 429.0 58.3 112.3 57.7 228.2 111.2 39.4 150.6 199.4 51.1 24.5 52.9 65.3 193.7 63.5 79.7 143.2 1344.2 301.9 21.7 35.6 359.2 56.2 62.9 61.5 180.7 105.6 28.6 134.1 115.3 37.0 16.0 33.6 33.8 120.5 35.1 50.2 85.2 994.9 156.8 NA NA 177.8 29.3 51.3 11.1 91.7 33.1 14.8 47.8 69.3 18.3 12.5 17.4 25.9 74.1 21.3 27.0 48.3 509.0 91.0 6.2 12.9 110.1 23.0 20.7 9.3 53.0 23.3 8.2 31.5 53.0 10.5 7.5 7.3 14.8 40.1 16.7 21.6 38.3 326.0 105.2 12.4 12.8 130.3 16.4 26.3 10.1 52.9 22.2 8.2 30.4 39.7 7.4 7.3 13.7 12.1 40.5 8.8 10.4 19.2 313.0 28.0 NA NA 30.6 5.6 5.4 2.5 13.5 6.9 2.0 8.9 NA 3.1 2.1 3.9 NA NA 2.4 3.1 5.5 83.5 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.3 1.3 1.7 17.2 3.4 4.0 3.1 10.6 4.7 2.7 7.4 11.7 2.6 1.1 2.2 2.3 8.2 4.4 3.7 8.2 63.3 1036.4 86.4 148.1 1270.9 193.5 284.2 155.7 633.4 308.3 104.2 412.5 503.4 131.2 71.5 131.8 159.3 493.8 153.0 198.1 351.1 3665.1
1983-05-01 316.6 42.3 63.7 422.6 67.8 120.5 64.9 253.2 112.5 41.4 153.9 200.5 54.8 25.4 55.0 68.9 204.1 64.5 81.1 145.6 1379.9 281.5 21.4 36.4 339.2 62.0 67.0 65.2 194.2 101.9 28.4 130.3 112.1 40.1 16.1 36.6 35.0 127.8 34.1 52.7 86.8 990.4 159.8 NA NA 181.3 35.1 53.6 12.0 100.7 33.9 15.6 49.5 69.3 20.2 12.7 18.0 26.9 77.8 21.3 27.5 48.9 527.5 91.6 6.1 13.1 110.8 26.8 22.5 10.5 59.8 24.5 8.1 32.6 56.0 11.4 7.7 8.1 15.3 42.4 16.3 23.2 39.5 341.1 106.9 12.7 13.2 132.8 19.6 29.4 11.1 60.2 25.0 9.1 34.0 46.0 8.3 7.8 14.2 12.9 43.2 9.1 11.4 20.5 336.8 27.5 NA NA 30.2 6.2 5.6 3.0 14.7 7.0 1.9 8.9 NA 3.1 2.1 3.9 NA NA 2.2 3.6 5.8 85.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.1 1.4 1.8 17.3 3.7 4.8 3.1 11.6 4.6 2.8 7.3 11.5 2.8 1.1 2.3 2.3 8.5 4.3 5.0 9.3 65.6 1014.2 85.0 152.4 1251.7 222.9 304.9 170.1 697.9 310.8 107.7 418.5 510.6 142.0 73.5 138.9 166.5 520.8 153.2 207.4 360.5 3760.0
1983-06-01 325.4 40.4 64.9 430.6 64.2 115.0 58.6 237.8 103.6 37.1 140.7 175.2 52.3 24.6 56.2 65.7 198.8 63.0 79.7 142.8 1325.8 290.6 20.8 34.2 345.6 57.0 66.2 60.2 183.3 90.3 25.6 115.9 100.1 38.2 16.1 35.9 33.7 123.8 34.9 46.4 81.3 950.0 158.8 NA NA 180.2 30.9 53.6 12.0 96.5 34.0 15.5 49.5 72.6 19.8 12.6 18.7 26.8 77.9 21.0 26.5 47.5 524.2 94.0 6.2 13.1 113.2 28.5 22.9 9.8 61.2 22.4 7.4 29.8 51.9 11.3 7.4 7.7 14.9 41.3 15.7 21.9 37.6 335.0 106.9 13.7 13.4 134.0 18.4 25.8 11.0 55.2 22.2 8.1 30.3 37.8 7.2 7.2 14.1 12.2 40.6 8.6 10.4 19.0 316.9 27.3 NA NA 30.2 6.4 5.2 2.5 14.1 6.7 1.9 8.6 NA 2.9 2.0 4.2 NA NA 2.2 3.5 5.7 83.0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 14.2 1.4 2.0 17.6 3.4 4.3 2.6 10.3 3.9 2.3 6.2 10.1 2.8 1.0 2.2 2.1 8.2 4.3 5.6 9.9 62.3 1033.9 83.7 151.6 1269.3 210.5 294.4 157.0 661.8 284.6 98.3 383.0 462.4 136.0 71.3 139.7 160.3 507.3 150.7 196.4 347.1 3630.8
1983-07-01 323.1 41.6 69.5 434.2 60.8 111.7 58.8 231.3 97.4 34.1 131.5 181.4 57.7 23.9 54.6 66.9 203.0 61.9 84.7 146.6 1328.1 297.6 21.3 36.2 355.2 54.9 64.0 59.9 178.8 95.1 26.6 121.7 103.4 39.0 16.2 36.9 34.2 126.4 35.8 49.8 85.6 971.0 162.9 NA NA 185.1 32.9 55.0 14.4 102.2 33.5 16.0 49.5 65.9 20.8 13.0 19.5 29.0 82.2 22.1 27.8 49.9 534.8 98.3 6.2 13.5 118.0 25.7 22.2 11.1 58.9 24.0 7.9 31.9 51.7 8.3 8.1 8.3 15.8 40.5 18.2 23.1 41.3 342.3 106.2 13.9 13.1 133.2 18.4 30.2 9.7 58.3 24.7 8.4 33.0 40.3 7.6 7.7 14.3 12.3 41.8 8.9 10.9 19.8 326.5 28.3 NA NA 31.3 5.9 5.1 2.7 13.7 6.0 1.8 7.8 NA 2.9 2.0 4.0 NA NA 2.2 4.4 6.7 83.9 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.6 1.5 2.1 17.2 3.8 4.2 2.8 10.8 4.0 2.5 6.5 10.4 3.0 1.1 2.3 2.3 8.7 4.6 6.3 10.8 64.5 1047.4 85.9 159.5 1292.8 203.9 293.4 159.6 656.9 286.2 97.7 384.0 468.3 141.0 72.5 140.9 165.6 519.9 154.7 209.8 364.5 3686.5
1983-08-01 338.1 42.2 67.9 448.2 64.8 117.2 64.8 246.9 96.3 34.0 130.2 179.7 61.5 25.0 54.6 70.4 211.5 64.7 85.2 149.9 1366.3 309.6 22.6 37.1 369.3 58.8 72.4 65.2 196.4 91.3 25.7 117.0 101.4 47.1 17.2 39.3 37.3 140.9 37.1 53.3 90.5 1015.5 167.3 NA NA 189.4 35.1 61.0 14.0 110.1 36.6 16.4 52.9 60.4 21.2 13.9 22.1 29.5 86.7 22.8 28.7 51.5 551.0 101.7 6.7 13.8 122.1 27.8 24.9 11.2 63.9 23.0 7.9 30.9 54.0 9.0 8.5 8.5 16.3 42.3 18.6 24.6 43.2 356.4 111.9 14.2 13.5 139.6 19.4 34.2 11.0 64.6 24.1 8.4 32.4 38.0 8.9 8.2 15.3 13.1 45.5 9.2 11.7 20.8 340.9 29.6 NA NA 32.6 6.4 5.8 3.1 15.3 6.5 1.9 8.3 NA 2.9 2.2 4.0 NA NA 2.5 4.7 7.1 88.1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.8 1.5 1.8 17.1 3.8 4.1 2.8 10.7 3.6 2.4 6.0 10.0 3.2 1.1 2.5 2.4 9.2 4.9 4.5 9.4 62.5 1089.4 88.5 159.1 1337.0 217.7 320.9 172.4 711.0 283.0 96.9 379.9 458.2 155.8 76.5 147.3 174.6 554.2 160.8 215.2 376.0 3816.3
1983-09-01 330.6 42.5 67.5 440.6 65.1 106.9 68.7 240.7 105.6 37.2 142.9 185.0 61.0 24.5 53.8 71.6 210.9 66.3 84.3 150.6 1370.8 310.2 22.4 37.4 370.0 57.4 69.7 66.4 193.6 94.7 26.5 121.3 105.2 46.1 16.9 38.3 37.2 138.5 36.8 54.0 90.8 1019.2 163.9 NA NA 185.1 34.6 55.0 15.1 104.7 37.0 17.5 54.5 73.9 20.5 13.4 21.5 29.6 85.1 22.8 27.7 50.5 553.9 99.1 7.0 13.4 119.5 25.8 22.8 12.3 61.0 24.4 8.2 32.6 52.3 9.1 8.3 8.2 16.4 42.0 18.4 23.8 42.3 349.7 111.3 14.8 13.2 139.3 19.6 30.1 12.1 61.9 25.6 9.2 34.8 40.3 7.6 8.2 15.2 13.6 44.5 9.8 11.7 21.5 342.3 29.2 NA NA 32.1 6.4 5.3 3.2 14.9 6.0 1.9 7.9 NA 2.9 2.0 4.2 NA NA 2.3 5.0 7.4 88.0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 13.5 1.5 2.1 17.1 3.8 4.0 3.1 10.9 3.6 2.5 6.1 10.3 3.2 1.0 2.3 2.4 8.9 4.5 6.4 10.9 64.1 1075.6 89.6 157.7 1322.8 213.9 295.1 181.4 690.3 298.5 103.5 402.0 482.7 152.4 74.9 144.6 176.0 547.9 162.0 215.6 377.6 3823.4
1983-10-01 351.1 45.0 66.0 462.1 66.3 114.4 84.1 264.8 97.9 37.3 135.2 194.4 56.9 24.6 55.6 74.9 212.0 63.7 80.1 143.8 1412.3 314.5 22.9 37.0 374.4 59.9 73.5 71.3 204.8 102.9 29.1 132.0 106.4 46.9 18.2 38.4 39.1 142.7 39.6 53.1 92.7 1053.0 167.2 NA NA 189.6 36.4 52.6 14.7 103.7 33.1 16.2 49.3 65.5 21.1 13.2 20.9 29.5 84.7 22.9 29.4 52.4 545.1 96.7 7.2 12.7 116.6 21.9 22.7 10.2 54.8 22.5 7.6 30.0 51.5 8.4 8.0 8.7 15.2 40.3 17.8 21.6 39.4 332.8 112.3 15.1 13.0 140.4 17.8 26.8 12.8 57.4 24.2 9.1 33.3 41.5 8.5 7.9 15.9 13.9 46.2 10.1 11.6 21.7 340.5 29.9 NA NA 33.0 6.3 4.9 3.3 14.5 6.4 1.9 8.4 NA 3.2 2.1 4.0 NA NA 2.5 5.1 7.5 88.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 16.6 1.5 2.4 20.5 3.4 5.0 3.3 11.7 3.4 2.5 5.9 11.2 3.1 1.3 2.3 2.7 9.4 5.5 7.2 12.8 71.4 1105.9 93.1 156.4 1355.4 213.3 301.1 200.2 714.6 291.8 104.0 395.8 485.3 149.9 75.8 146.9 180.8 553.5 163.1 211.0 374.1 3878.7
1983-11-01 361.5 45.8 67.2 474.5 72.8 136.5 101.2 310.4 110.2 41.0 151.2 224.9 59.3 27.8 57.7 83.4 228.2 69.4 82.9 152.3 1541.6 336.8 24.0 38.4 399.1 64.3 80.3 82.8 227.4 109.7 30.0 139.6 123.1 48.9 19.4 40.7 42.6 151.7 42.0 53.9 95.8 1136.8 175.6 NA NA 198.2 37.2 61.7 16.7 115.6 37.6 17.5 55.1 77.6 23.3 14.6 22.1 32.3 92.2 24.6 29.9 54.5 593.3 101.2 7.6 12.8 121.6 24.2 27.0 11.8 63.0 24.6 7.9 32.5 64.3 9.2 8.6 8.6 16.1 42.5 18.2 21.8 40.1 363.9 115.0 15.4 13.2 143.7 18.8 31.4 15.5 65.7 26.0 9.7 35.7 47.9 9.2 8.8 16.4 15.5 49.8 10.8 11.7 22.5 365.3 31.5 NA NA 34.7 7.2 6.2 3.4 16.8 7.0 2.1 9.1 NA 3.4 2.3 4.0 NA NA 2.8 5.2 8.0 97.7 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 17.3 1.5 2.4 21.1 4.0 5.5 3.6 13.1 3.7 2.8 6.5 12.6 3.3 1.5 2.8 3.2 10.8 6.7 7.1 13.8 78.0 1155.9 95.4 159.6 1410.9 230.1 350.1 235.3 815.5 320.3 111.4 431.7 568.7 158.3 83.7 153.3 198.8 594.1 175.3 215.3 390.6 4211.5

I have selected "A3349337W" as the timeseries from the retail data set for this exercise.

myts <- ts(retaildata[,"A3349337W"],frequency=12, start=c(1982,4))

myts
##        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
## 1982                    53.6  55.4  48.4  52.1  54.2  53.6  58.0  67.2 146.3
## 1983  66.6  59.2  67.3  57.7  64.9  58.6  58.8  64.8  68.7  84.1 101.2 192.3
## 1984  73.7  69.6  77.7  68.5  70.0  60.5  60.2  70.0  69.5  81.5  96.5 179.4
## 1985  69.4  69.8  74.1  71.9  83.6  68.8  71.8  79.4  76.0  97.0 126.8 221.2
## 1986  90.3  89.8  89.6  91.9  96.0  89.3  79.4  89.1  88.1 116.8 128.6 235.4
## 1987 103.9  97.3  97.9  97.2 106.5  88.2  97.7 100.2 110.8 137.3 150.5 248.8
## 1988 126.6 119.4 123.6 108.8 121.0 113.9 110.9 124.3 118.5 143.9 172.1 307.4
## 1989 160.7 155.2 161.0 149.3 165.6 140.1 128.2 140.4 130.2 143.3 185.3 228.9
## 1990  96.4  95.0 103.8  97.1 104.6 100.7  98.2 106.6  96.7 113.3 126.2 159.5
## 1991  89.1  99.6 129.0 125.6 127.3 111.7 114.1 118.0 119.6 121.5 128.5 151.4
## 1992 100.1 108.2 113.2 108.0  98.2  95.2 101.4  93.5 112.0 118.9 125.7 154.7
## 1993 100.7 102.8 113.5  99.2  95.4  89.3  84.4  91.1 102.2 101.4 108.5 179.0
## 1994 111.0 121.4 125.6 116.2 125.1 119.1 117.5 123.8 134.5 141.0 145.2 180.7
## 1995 120.8 121.0 132.6 116.3 113.2 120.2 124.3 134.0 140.6 163.7 176.2 225.4
## 1996 157.5 147.7 158.1 152.4 171.0 158.0 174.0 157.5 167.0 181.0 189.6 249.8
## 1997 168.0 154.9 169.9 159.8 172.7 154.1 144.9 141.3 164.3 162.7 172.8 248.7
## 1998 157.0 145.0 158.6 145.9 146.8 140.2 135.8 141.7 158.7 148.4 148.0 183.0
## 1999 133.1 120.5 132.2 126.0 141.0 135.0 143.7 144.4 171.7 185.5 167.9 200.7
## 2000 169.7 163.2 167.6 148.7 161.4 188.5 158.3 174.5 193.2 194.5 209.7 266.3
## 2001 209.6 185.2 202.2 200.0 200.3 200.3 193.6 211.4 218.2 236.3 230.6 291.0
## 2002 219.9 196.6 218.7 216.8 205.5 198.2 233.9 246.2 259.8 277.3 294.3 341.9
## 2003 247.0 229.3 250.3 241.6 247.0 258.7 271.3 291.1 312.7 324.6 315.2 360.8
## 2004 258.9 246.5 260.9 249.0 256.5 257.4 275.4 269.8 279.8 307.3 323.9 361.1
## 2005 281.8 250.6 274.1 270.3 268.2 264.0 266.9 298.6 303.1 329.4 345.6 395.2
## 2006 288.0 277.3 302.8 288.5 290.4 275.4 262.4 272.9 279.7 299.3 313.3 341.6
## 2007 286.4 268.4 286.6 260.0 273.0 248.5 259.7 272.2 293.6 294.9 294.3 339.3
## 2008 263.0 246.2 255.2 240.2 239.6 226.9 238.7 253.1 271.3 283.1 299.0 360.2
## 2009 289.3 249.6 272.1 272.9 279.4 267.8 273.1 307.7 318.2 334.0 325.0 348.9
## 2010 309.2 272.6 311.1 298.2 313.1 305.8 307.3 330.9 362.8 361.7 364.2 395.4
## 2011 311.6 283.7 322.2 310.8 319.5 305.1 308.9 355.6 384.9 401.1 382.1 409.0
## 2012 334.0 292.1 309.6 305.8 325.0 314.2 327.2 363.7 406.9 397.1 379.6 428.0
## 2013 340.0 293.9 330.7 290.7 291.8 281.1 309.8 344.6 360.7 384.7 367.9 430.7
title <- 'Retail Sales for Category = A3349337W'

# Timeseries plot before Transformation:
autoplot(myts,ylab="$ Sales Turnover",xlab="Year") + ggtitle(title)

X11 Decomposition on Retail Data set:

myts %>% seas(x11="") -> retail_fit
autoplot(retail_fit) +
  ggtitle(paste("X11 decomposition of ", title))

Plotting Seasonally Adjusted data with X11 Decomposition:

autoplot(myts, series="Data") +
  autolayer(trendcycle(retail_fit), series="Trend") +
  autolayer(seasadj(retail_fit), series="Seasonally Adjusted") +
  xlab("Year") + ylab("New orders index") +
  ggtitle(paste("X11 decomposition of ", title)) +
  scale_colour_manual(values=c("gray","blue","red"),
             breaks=c("Data","Seasonally Adjusted","Trend"))

Observations:

  • One interesting observation based on above plots which I didn't notice in prior assignments is the variation in seasonality over different windows in the time series. Data before 1990, show a very narrow spikes pattern with highest peaks in seasonality. such high narrow spikes most likely resulted from outliers. Seasonally adjusted data smooths out these outliers as shown in the 2nd plot. During this period, a steady overall increasing trend can be observed.
  • Between 1990-2000, a second seasonal pattern is visible with much more consistent peaks and valleys.
  • After 2000 also, a soewhat consistent seasonal pattern can be observed with two different patterns before and after 2009. During this period, there is a consistent positive trend in sales visible with litle bit of dip in 2009.