Forecasting: Principles and Practice.
Instructions
From the book Forecasting Principles and Practice by Hyndman, R. & Athanasopoulus, G.
Please submit exercises 6.2
and 6.3
from the Hyndman online Forecasting book. Please submit both your Rpubs link as well as attach the .rmd file with your code.
Exercises
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?
From the above plot, we can identify what seems to be seasonal fluctuations based on a 12 month period and an upward trend-cycle with a downward tendency towards the end.
b)
Use a classical multiplicative decomposition to calculate the trend-cycle and seasonal indices.
decompose(plastics, type="multiplicative")
Seasonal indices
## 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-Cycle indices
## 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
c)
Do the results support the graphical interpretation from part a?
Yes, the results support the graphical interpretation from part a); that is, we can notice how the indices in the Seasonal trend repeat themselves in yearly basis and we can notice how the Trend-Cycle values are increasing over time, with a decreasing tendency towards the end.
d)
Compute and plot the seasonally adjusted data.
seasadj(mdecomp)
## Jan Feb Mar Apr May Jun Jul
## 1 967.3468 981.2262 999.3182 986.4758 985.8925 956.7826 1001.1759
## 2 966.0431 985.4495 996.7427 1023.8257 1051.9377 1057.0417 1108.5982
## 3 1168.1168 1116.3736 1139.6864 1158.9443 1152.4413 1146.0648 1119.7701
## 4 1239.8204 1212.1029 1207.9388 1218.2647 1219.4437 1229.0378 1277.0364
## 5 1342.8129 1452.8342 1450.0416 1411.6051 1405.1361 1414.8628 1384.4587
## Aug Sep Oct Nov Dec
## 1 992.4139 981.0263 951.4241 978.9119 939.8819
## 2 1100.9592 1089.0366 1090.2260 1074.6860 1081.5244
## 3 1171.9625 1196.2349 1222.2981 1179.5334 1227.9683
## 4 1269.0820 1302.6210 1345.9580 1414.4319 1451.2352
## 5 1312.3369 1240.9008 1194.5377 1128.1178 1215.9647
autoplot(mdecomp$seasonaladj)
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.ts[21] + 500
From the above graph, we can notice how the outlier or unusual observation towards the end of year 2 is now more clearly seen in the Seasonally Adjusted 500 component (red color); also, we notice how the outlier affect the Trend-Cycle around that area (Orange vs Purple); another interesting observation is that Seasonality gets affected by it as well as seeing (Blue vs Red).
f)
Does it make any difference if the outlier is near the end rather than in the middle of the time series?
plastics.ts[68] + 500
plastics.ts[30] + 500
Interestingly enough, from the above graphs; it seems that an outlier does make a difference if the outlier is near the end rather than in the middle of the time series. We can notice how the Seasonally Adjusted path change on various locations because of it (red vs blue color) if the outlier is located towards the center.
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?
read_excel(retail.xlsx)
My previously selected time series was A3349627V
; and it represents the Turnover in New South Wales about Liquor retailing.
Raw Data Analysis
seas(myts, x11="")
autoplot(myts)
Subseries plot
Box-Cox Transformation Analysis
seas(myts.BC, x11="")
autoplot(myts.BC)
Subseries plot
For this particular data set, It doesn’t seems to be too noticeable, but the seasonal pattern on both, the raw data and the box-cox transformation, reveal a small change in the season over time for the time series. This is interesting to me, since I have not previously noticed on any of my previous examples; in this case, the season seems to follow some sort of a wave pattern for all the series.
References
Hyndman, R. & Athanasopoulos, G. 2019. Forecasting: Principles and Practice. Australia: Monash University. https://otexts.com/fpp2/.
R Core Team. 2016. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.