Libraries

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

Forecasting: Principles & Practice

Section 7.8 Exercise 1

DataSet: pigs

Description: - The number of pigs slaughtered in Victoria each month.

pigs
##         Jan    Feb    Mar    Apr    May    Jun    Jul    Aug    Sep    Oct
## 1980  76378  71947  33873  96428 105084  95741 110647 100331  94133 103055
## 1981  76889  81291  91643  96228 102736 100264 103491  97027  95240  91680
## 1982  76892  85773  95210  93771  98202  97906 100306  94089 102680  77919
## 1983  81225  88357 106175  91922 104114 109959  97880 105386  96479  97580
## 1984  90974  98981 107188  94177 115097 113696 114532 120110  93607 110925
## 1985 103069 103351 111331 106161 111590  99447 101987  85333  86970 100561
## 1986  82719  79498  74846  73819  77029  78446  86978  75878  69571  75722
## 1987  63292  59380  78332  72381  55971  69750  85472  70133  79125  85805
## 1988  69069  79556  88174  66698  72258  73445  76131  86082  75443  73969
## 1989  66269  73776  80034  70694  81823  75640  75540  82229  75345  77034
## 1990  75982  78074  77588  84100  97966  89051  93503  84747  74531  91900
## 1991  81022  78265  77271  85043  95418  79568 103283  95770  91297 101244
## 1992  93866  95171 100183 103926 102643 108387  97077  90901  90336  88732
## 1993  73292  78943  94399  92937  90130  91055 106062 103560 104075 101783
## 1994  82413  83534 109011  96499 102430 103002  91815  99067 110067 101599
## 1995  88905  89936 106723  84307 114896 106749  87892 100506              
##         Nov    Dec
## 1980  90595 101457
## 1981 101259 109564
## 1982  93561 117062
## 1983 109490 110191
## 1984 103312 120184
## 1985  89543  89265
## 1986  64182  77357
## 1987  81778  86852
## 1988  78139  78646
## 1989  78589  79769
## 1990  81635  89797
## 1991 114525 101139
## 1992  83759  99267
## 1993  93791 102313
## 1994  97646 104930
## 1995

Timeseries data plot: pigs

autoplot(pigs,ylab="No. of Pigs Slaughtered",xlab="Year") + ggtitle("Pigs Slaughtered Trend in Victoria, Australia")

  1. Use the ses() function in R to find the optimal values of \(\alpha\) and \({ l }_{ 0 }\), and generate forecasts for the next four months.
# Estimate parameters & generate 4 months forecast (h=4)
fit <- ses(pigs, h=4)
summary(fit)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = pigs, h = 4) 
## 
##   Smoothing parameters:
##     alpha = 0.2971 
## 
##   Initial states:
##     l = 77260.0561 
## 
##   sigma:  10308.58
## 
##      AIC     AICc      BIC 
## 4462.955 4463.086 4472.665 
## 
## Error measures:
##                    ME    RMSE      MAE       MPE     MAPE      MASE       ACF1
## Training set 385.8721 10253.6 7961.383 -0.922652 9.274016 0.7966249 0.01282239
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Sep 1995       98816.41 85605.43 112027.4 78611.97 119020.8
## Oct 1995       98816.41 85034.52 112598.3 77738.83 119894.0
## Nov 1995       98816.41 84486.34 113146.5 76900.46 120732.4
## Dec 1995       98816.41 83958.37 113674.4 76092.99 121539.8

Based on the above output of ses() -

Optimal value of smoothing parameter \(\alpha\) is 0.2971 and \({ l }_{ 0 }\) is 77260.0561.

  1. Compute a 95% prediction interval for the first forecast using \(\overset { \^ }{ y } \pm 1.96s\) where s is the standard deviation of the residuals. Compare your interval with the interval produced by R.

95% Confidence Interval

# Standard Deviation of the Residuals
sd(residuals(fit))
## [1] 10273.69
cat("Floor Value of the 95% Prediction interval for the point forecast:",98816.41 - 1.96*sd(residuals(fit)))
## Floor Value of the 95% Prediction interval for the point forecast: 78679.97
cat("Ceiling Value of the 95% Prediction interval for the point forecast:",98816.41 + 1.96*sd(residuals(fit)))
## Ceiling Value of the 95% Prediction interval for the point forecast: 118952.8

Comparing the Prediction interval values calculayed above and those generated by R, lower value of the calculated interval is greater and ceiling value is lesser. So the calculated prediction interval appear to be smaller than the range derived by R.

Section 7.8 Exercise 5

DataSet: books

Description: - Data set books contains the daily sales of paperback and hardcover books at the same store.

books
## Time Series:
## Start = 1 
## End = 30 
## Frequency = 1 
##    Paperback Hardcover
##  1       199       139
##  2       172       128
##  3       111       172
##  4       209       139
##  5       161       191
##  6       119       168
##  7       195       170
##  8       195       145
##  9       131       184
## 10       183       135
## 11       143       218
## 12       141       198
## 13       168       230
## 14       201       222
## 15       155       206
## 16       243       240
## 17       225       189
## 18       167       222
## 19       237       158
## 20       202       178
## 21       186       217
## 22       176       261
## 23       232       238
## 24       195       240
## 25       190       214
## 26       182       200
## 27       222       201
## 28       217       283
## 29       188       220
## 30       247       259

The task is to forecast the next four days' sales for paperback and hardcover books.

  1. Plot the series and discuss the main features of the data.

Timeseries data plot: books

autoplot(books,ylab="Books Sales",xlab="Days") + ggtitle("Trend of Books Sales")

Observations

  • Overall there are more sales in Hardcover books than the Paperback books.
  • Both types of books have a pattern resembling a positive trend.
  • The peaks and troughs happens at irregular intervals therefore there is not any reason to conclude there is seasonality present.
  1. Use the ses() function to forecast each series, and plot the forecasts.

Books Sales Forecast using SES: Paperback

# Forecast for 4 days
ses_p_fit <- ses(books[,"Paperback"], h=4)
summary(ses_p_fit)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = books[, "Paperback"], h = 4) 
## 
##   Smoothing parameters:
##     alpha = 0.1685 
## 
##   Initial states:
##     l = 170.8271 
## 
##   sigma:  34.8183
## 
##      AIC     AICc      BIC 
## 318.9747 319.8978 323.1783 
## 
## Error measures:
##                    ME     RMSE     MAE       MPE     MAPE      MASE       ACF1
## Training set 7.175981 33.63769 27.8431 0.4736071 15.57784 0.7021303 -0.2117522
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       207.1097 162.4882 251.7311 138.8670 275.3523
## 32       207.1097 161.8589 252.3604 137.9046 276.3147
## 33       207.1097 161.2382 252.9811 136.9554 277.2639
## 34       207.1097 160.6259 253.5935 136.0188 278.2005
# Forecast Plot
autoplot(ses_p_fit) +
  autolayer(fitted(ses_p_fit), series='Fitted') +
  ggtitle('SES Fit and Forecast of Paperback Sales') +
  xlab('Day') +
  ylab('Books Sales')

Books Sales Forecast using SES: Hardcover

# Forecast for 4 days
ses_h_fit <- ses(books[,"Hardcover"], h=4)
summary(ses_h_fit)
## 
## Forecast method: Simple exponential smoothing
## 
## Model Information:
## Simple exponential smoothing 
## 
## Call:
##  ses(y = books[, "Hardcover"], h = 4) 
## 
##   Smoothing parameters:
##     alpha = 0.3283 
## 
##   Initial states:
##     l = 149.2861 
## 
##   sigma:  33.0517
## 
##      AIC     AICc      BIC 
## 315.8506 316.7737 320.0542 
## 
## Error measures:
##                    ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set 9.166735 31.93101 26.77319 2.636189 13.39487 0.7987887 -0.1417763
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       239.5601 197.2026 281.9176 174.7799 304.3403
## 32       239.5601 194.9788 284.1414 171.3788 307.7414
## 33       239.5601 192.8607 286.2595 168.1396 310.9806
## 34       239.5601 190.8347 288.2855 165.0410 314.0792
# Forecast Plot
autoplot(ses_h_fit) +
  autolayer(fitted(ses_h_fit), series='Fitted') +
  ggtitle('SES Fit and Forecast of Hardcover Sales') +
  xlab('Day') +
  ylab('Books Sales')

  1. Compute the RMSE values for the training data in each case.

RMSE Values of Training Data Set

cateory <- c("Paperback","Hardcover")

ses_rmse <- c(accuracy(ses_p_fit)[,"RMSE"],accuracy(ses_h_fit)[,"RMSE"]) 

cat("RMSE Value for the Paperback data set:",accuracy(ses_p_fit)[,"RMSE"])
## RMSE Value for the Paperback data set: 33.63769
cat("RMSE Value for the Hardcover data set:",accuracy(ses_h_fit)[,"RMSE"])
## RMSE Value for the Hardcover data set: 31.93101

Section 7.8 Exercise 6

We will continue with the daily sales of paperback and hardcover books in data set books.

  1. Apply Holt's linear method to the paperback and hardback series and compute four-day forecasts in each case.

Holt's Linear Trend method for Forecast: Paperback

holt_p_fit <- holt(books[,"Paperback"], h=4)

summary(holt_p_fit)
## 
## Forecast method: Holt's method
## 
## Model Information:
## Holt's method 
## 
## Call:
##  holt(y = books[, "Paperback"], h = 4) 
## 
##   Smoothing parameters:
##     alpha = 1e-04 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 170.699 
##     b = 1.2621 
## 
##   sigma:  33.4464
## 
##      AIC     AICc      BIC 
## 318.3396 320.8396 325.3456 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -3.717178 31.13692 26.18083 -5.508526 15.58354 0.6602122
##                    ACF1
## Training set -0.1750792
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       209.4668 166.6035 252.3301 143.9130 275.0205
## 32       210.7177 167.8544 253.5811 145.1640 276.2715
## 33       211.9687 169.1054 254.8320 146.4149 277.5225
## 34       213.2197 170.3564 256.0830 147.6659 278.7735
autoplot(books[,"Paperback"]) +
  autolayer(fitted(holt_p_fit), series='Fitted') +
  autolayer(holt_p_fit, series="Holt's method", PI=TRUE) +
  ggtitle("4 Days Paperback Book Sales Forecasts from Holt's method") + xlab("Days") +
  ylab("Book Sales") +
  guides(colour=guide_legend(title="Forecast"))

Holt's Linear Trend method for Forecast: Hardcover

holt_h_fit <- holt(books[,"Hardcover"], h=4)

summary(holt_h_fit)
## 
## Forecast method: Holt's method
## 
## Model Information:
## Holt's method 
## 
## Call:
##  holt(y = books[, "Hardcover"], h = 4) 
## 
##   Smoothing parameters:
##     alpha = 1e-04 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 147.7935 
##     b = 3.303 
## 
##   sigma:  29.2106
## 
##      AIC     AICc      BIC 
## 310.2148 312.7148 317.2208 
## 
## Error measures:
##                      ME     RMSE      MAE       MPE    MAPE      MASE
## Training set -0.1357882 27.19358 23.15557 -2.114792 12.1626 0.6908555
##                     ACF1
## Training set -0.03245186
## 
## Forecasts:
##    Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## 31       250.1739 212.7390 287.6087 192.9222 307.4256
## 32       253.4765 216.0416 290.9113 196.2248 310.7282
## 33       256.7791 219.3442 294.2140 199.5274 314.0308
## 34       260.0817 222.6468 297.5166 202.8300 317.3334
autoplot(books[,"Hardcover"]) +
  autolayer(fitted(holt_h_fit), series='Fitted') +
  autolayer(holt_h_fit, series="Holt's method", PI=TRUE) +
  ggtitle("4 Days Hardcover Book Sales Forecasts from Holt's method") + xlab("Days") +
  ylab("Book Sales") +
  guides(colour=guide_legend(title="Forecast"))

  1. Compare the RMSE measures of Holt's method for the two series to those of simple exponential smoothing in the previous question. (Remember that Holt's method is using one more parameter than SES.) Discuss the merits of the two forecasting methods for these data sets.

Comparison of Forecasting Methods: SES Vs. Holt's

holts_rmse <- c(accuracy(holt_p_fit)[,"RMSE"],accuracy(holt_h_fit)[,"RMSE"]) 

cat("RMSE Value for the Paperback data set:",accuracy(holt_p_fit)[,"RMSE"])
## RMSE Value for the Paperback data set: 31.13692
cat("RMSE Value for the Hardcover data set:",accuracy(holt_h_fit)[,"RMSE"])
## RMSE Value for the Hardcover data set: 27.19358
RMSECompTable <- cbind(cateory,ses_rmse,holts_rmse) 
colnames(RMSECompTable) <- c("BookCategory","RMSE-SES","RMSE-Holt's")

RMSECompTable %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="150px")
BookCategory RMSE-SES RMSE-Holt's
Paperback 33.637686782912 31.1369230162347
Hardcover 31.9310149844547 27.1935779818511

After carefully reviewing the above plots and the RMSE comaprison table -

  • Holt's Linear Trend method generated smaller RMSE than the SES model for both books categories
  • SES method is better suited for data sets without any visible trend component. But for Book Sales data, inspte of having plenty of peaks and valleys for both the categories, there is a visible positive trend in data. Holt's method accounts for the Trend component of a time series through an additional smoothing parameter \({ \beta }^{ * }\) compared to SES method.
  • So based on lower RMSE and analyzing the plots associated with Holt's method, I think Holt's method is better suited in forecasting the books data sets.
  1. Compare the forecasts for the two series using both methods. Which do you think is best?

Forecast comparision: SES Vs. Holt's:

  • SES method generated "flat" forecasts completely ignoring the strong positive trends in both the books categories.
  • Holt's method captured the positive trend as discussed in the previous section and applied the calculated slope in generating forecasts for 4 days of sales.
  • I think Holt's method generated forecasts are more reliable since it captured the inherent trend component in the training data.
  1. Calculate a 95% prediction interval for the first forecast for each series, using the RMSE values and assuming normal errors. Compare your intervals with those produced using ses and holt.

95% Prediction Interval Comparison based on RMSE

Assuming normally distributed errors, we can construct the 95% prediction interval using \(\overset { \^ }{ y } \pm 1.96*RMSE\) equation -

# First Point Forecasts
ses_p_fit_1 <- ses_p_fit$mean[1]
ses_h_fit_1 <- ses_h_fit$mean[1]
holt_p_fit_1 <- holt_p_fit$mean[1]
holt_h_fit_1 <- holt_h_fit$mean[1]


#### Derived 95% Prediction Interval Based on RMSE

## Paperback Books - SES - R Generated
ses_lower_p_r <- ses_p_fit$lower[1,2]
ses_upper_p_r <- ses_p_fit$upper[1,2]

## Paperback Books - SES - Calculated 
ses_lower_p <- ses_p_fit$mean[1] - 1.96 * accuracy(ses_p_fit)[,"RMSE"]
ses_upper_p <- ses_p_fit$mean[1] + 1.96 * accuracy(ses_p_fit)[,"RMSE"]


## Hardcover Books - SES - R Generated
ses_lower_h_r <- ses_h_fit$lower[1,2]
ses_upper_h_r <- ses_h_fit$upper[1,2]

## Hardcover Books - SES
ses_lower_h <- ses_h_fit$mean[1] - 1.96 * accuracy(ses_h_fit)[,"RMSE"]
ses_upper_h <- ses_h_fit$mean[1] + 1.96 * accuracy(ses_h_fit)[,"RMSE"]


## Paperback Books - Holt's - R Generated
holt_lower_p_r <- holt_p_fit$lower[1,2]
holt_upper_p_r <- holt_p_fit$upper[1,2]

## Paperback Books - Holt
holt_lower_p <- holt_p_fit$mean[1] - 1.96 * accuracy(holt_p_fit)[,"RMSE"]
holt_upper_p <- holt_p_fit$mean[1] + 1.96 * accuracy(holt_p_fit)[,"RMSE"]

## Hardcover Books - Holt's - R Generated
holt_lower_h_r <- holt_h_fit$lower[1,2]
holt_upper_h_r <- holt_h_fit$upper[1,2]

## Hardcover Books - Holt
holt_lower_h <- holt_h_fit$mean[1] - 1.96 * accuracy(holt_h_fit)[,"RMSE"]
holt_upper_h <- holt_h_fit$mean[1] + 1.96 * accuracy(holt_h_fit)[,"RMSE"]

Col1 <- c(ses_p_fit_1, ses_lower_p_r, ses_upper_p_r)
Col2 <- c(ses_p_fit_1, ses_lower_p, ses_upper_p)
Col3 <- c(holt_p_fit_1, holt_lower_p_r, holt_upper_p_r)
Col4 <- c(holt_p_fit_1, holt_lower_p, holt_upper_p)

Col5 <- c(ses_h_fit_1, ses_lower_h_r, ses_upper_h_r)
Col6 <- c(ses_h_fit_1, ses_lower_h, ses_upper_h)
Col7 <- c(holt_h_fit_1, holt_lower_h_r, holt_upper_h_r)
Col8 <- c(holt_h_fit_1, holt_lower_h, holt_upper_h)



df <- data.frame(Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8)
df[4,] <- df[3,] - df[2,]

colnames(df) <- c('R - SES', 'Calculated - SES', 'R - Holt','Calculated - Holt', 'R - SES', 'Calculated - SES', 'R - Holt','Calculated - Holt')
row.names(df) <- c('Point Forecast', '95% - Lower', '95% - Upper', 'Interval Range')

kable(df) %>% 
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% 
  add_header_above(c(' ', 'Paperback Forecast' = 4, 'Hardcover Forecost' = 4)) %>% scroll_box(width="100%",height="300px")
Paperback Forecast
Hardcover Forecost
R - SES Calculated - SES R - Holt Calculated - Holt R - SES Calculated - SES R - Holt Calculated - Holt
Point Forecast 207.1097 207.1097 209.4668 209.4668 239.5601 239.5601 250.1739 250.1739
95% - Lower 138.8670 141.1798 143.9130 148.4384 174.7799 176.9753 192.9222 196.8745
95% - Upper 275.3523 273.0395 275.0205 270.4951 304.3403 302.1449 307.4256 303.4733
Interval Range 136.4853 131.8597 131.1076 122.0567 129.5604 125.1696 114.5034 106.5988

Section 7.8 Exercise 7

For this exercise use data set eggs, the price of a dozen eggs in the United States from 1900-1993. Experiment with the various options in the holt() function to see how much the forecasts change with damped trend, or with a Box-Cox transformation. Try to develop an intuition of what each argument is doing to the forecasts.

[Hint: use h=100 when calling holt() so you can clearly see the differences between the various options when plotting the forecasts.]

Which model gives the best RMSE?

DataSet: eggs

Description: - The price of a dozen eggs in the United States from 1900-1993.

eggs
## Time Series:
## Start = 1900 
## End = 1993 
## Frequency = 1 
##  [1] 276.79 315.42 314.87 321.25 314.54 317.92 303.39 288.62 292.44 320.92
## [11] 323.38 270.77 301.77 282.99 295.06 276.47 292.80 358.78 345.82 345.42
## [21] 314.10 228.74 215.76 224.67 225.93 250.87 236.24 209.12 237.31 251.67
## [31] 205.36 167.21 150.42 154.09 183.67 246.66 227.58 214.60 208.41 181.21
## [41] 185.67 230.86 266.34 310.29 267.18 303.03 278.46 293.36 283.62 274.26
## [51] 218.12 265.62 226.70 258.00 196.98 213.38 209.17 184.50 192.61 155.83
## [61] 176.32 172.13 161.63 163.00 157.63 154.50 174.28 135.17 141.36 157.83
## [71] 145.65 112.06 106.85 170.91 156.26 140.78 148.35 132.61 115.72 116.07
## [81]  98.76 100.33  89.12  88.67 100.58  76.84  81.10  69.60  64.55  80.36
## [91]  79.79  74.79  64.86  62.27

Timeseries data plot: pigs

autoplot(eggs,ylab="Price of a Dozen Eggs",xlab="Year") + ggtitle("Price Trend of a Dozen Eggs in US (1900-1993)")

Holt's Linear Trend Model Analysis:

Model1 - Default Values
model1_fit <- holt(eggs, h=100)

model1_fit[['model']]
## Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100) 
## 
##   Smoothing parameters:
##     alpha = 0.8124 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 314.7232 
##     b = -2.7222 
## 
##   sigma:  27.1665
## 
##      AIC     AICc      BIC 
## 1053.755 1054.437 1066.472
accuracy(model1_fit)
##                      ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 0.04499087 26.58219 19.18491 -1.142201 9.653791 0.9463626
##                    ACF1
## Training set 0.01348202
autoplot(eggs) +
  autolayer(fitted(model1_fit), series='Fitted') +
  autolayer(model1_fit, series="Holt's method", PI=TRUE) +
  ggtitle("Dozen Eggs Price Forecast from Holt's method - Default") + xlab("Year") +
  ylab("Dozen Egg Price") +
  guides(colour=guide_legend(title="Forecast"))

Model2 - Damped Forecast
model2_fit <- holt(eggs, h=100, damped=TRUE, phi = 0.98)

model2_fit[['model']]
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.98) 
## 
##   Smoothing parameters:
##     alpha = 0.8226 
##     beta  = 1e-04 
##     phi   = 0.98 
## 
##   Initial states:
##     l = 314.1262 
##     b = -3.8058 
## 
##   sigma:  27.3981
## 
##      AIC     AICc      BIC 
## 1054.301 1054.983 1067.018
accuracy(model2_fit)
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -1.196504 26.65951 19.49533 -2.127729 9.978595 0.9616751
##                     ACF1
## Training set 0.009340454
autoplot(eggs, coverage.col = "gray50") +
  autolayer(fitted(model2_fit), series='Fitted') +
  autolayer(model2_fit, series="Holt's method", PI=TRUE) +
  ggtitle("Dozen Eggs Price Forecast from Holt's method - Damped Forecast") + xlab("Year") +
  ylab("Dozen Egg Price") +
  guides(colour=guide_legend(title="Forecast"))

Model3 - With Box Cox Transformation
lambda <- BoxCox.lambda(eggs)

model3_fit <-  holt(eggs, h=100, lambda = lambda)

model3_fit[['model']]
## Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, lambda = lambda) 
## 
##   Box-Cox transformation: lambda= 0.3956 
## 
##   Smoothing parameters:
##     alpha = 0.809 
##     beta  = 1e-04 
## 
##   Initial states:
##     l = 21.0322 
##     b = -0.1144 
## 
##   sigma:  1.0549
## 
##      AIC     AICc      BIC 
## 443.0310 443.7128 455.7475
accuracy(model3_fit)
##                     ME     RMSE      MAE       MPE     MAPE      MASE
## Training set 0.7736844 26.39376 18.96387 -1.072416 9.620095 0.9354593
##                    ACF1
## Training set 0.03887152
autoplot(eggs) +
  autolayer(fitted(model3_fit), series='Fitted') +
  autolayer(model3_fit, series="Holt's method", PI=TRUE) +
  ggtitle("Dozen Eggs Price Forecast from Holt's method - Boxcox Transform") + xlab("Year") +
  ylab("Dozen Egg Price") +
  guides(colour=guide_legend(title="Forecast"))

Model4 - With Box Cox Transformation and Damped
lambda <- BoxCox.lambda(eggs)

model4_fit <-  holt(eggs, h=100, damped=TRUE, phi = 0.98, lambda = lambda)

model4_fit[['model']]
## Damped Holt's method 
## 
## Call:
##  holt(y = eggs, h = 100, damped = TRUE, phi = 0.98, lambda = lambda) 
## 
##   Box-Cox transformation: lambda= 0.3956 
## 
##   Smoothing parameters:
##     alpha = 0.8363 
##     beta  = 1e-04 
##     phi   = 0.98 
## 
##   Initial states:
##     l = 21.211 
##     b = -0.1317 
## 
##   sigma:  1.0668
## 
##      AIC     AICc      BIC 
## 444.0850 444.7668 456.8015
accuracy(model4_fit)
##                      ME     RMSE      MAE       MPE     MAPE      MASE
## Training set -0.7938125 26.48745 19.32707 -2.022886 9.936089 0.9533751
##                    ACF1
## Training set 0.01381863
autoplot(eggs) +
  autolayer(fitted(model3_fit), series='Fitted') +
  autolayer(model4_fit, series="Holt's method", PI=TRUE) +
  ggtitle("Dozen Eggs Price Forecast from Holt's method - Boxcox Transform + Damped") + xlab("Year") +
  ylab("Dozen Egg Price") +
  guides(colour=guide_legend(title="Forecast"))

Model Accuracy Comparisons:

df <- rbind(accuracy(model1_fit), accuracy(model2_fit), accuracy(model3_fit), accuracy(model4_fit))
row.names(df) <- c('Default', 'Damped', 'Box-Cox','Damped & Box-Cox')
kable(df) %>% 
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"))
ME RMSE MAE MPE MAPE MASE ACF1
Default 0.0449909 26.58219 19.18491 -1.142201 9.653791 0.9463626 0.0134820
Damped -1.1965042 26.65951 19.49533 -2.127729 9.978595 0.9616751 0.0093405
Box-Cox 0.7736844 26.39376 18.96387 -1.072416 9.620095 0.9354593 0.0388715
Damped & Box-Cox -0.7938125 26.48745 19.32707 -2.022886 9.936089 0.9533751 0.0138186

Observations:

  • I have built 4 models with holt() method with various parameter options.
  • In the 1st model, I have used default parameters and it can be observed that Holt's default method tends to generate forecast with a constand trend over a long forecast period (h=100) which in this case is a decreasing trend. This leads to negative price for dozen eggs around 2025. Clearly this doesn't make much sense.
  • To avoid situation listed above, in the 2nd model I have used Damped = TRUE option (phi=0.98). This option made a clear impact in the forecast and it dampend the forecast appropriately.
  • In the 3rd model, I have used BoxCox transformation (with lambda=0.3956) without damped option. In this model the smoothing parameter alpha has higher value than previous 2 models.
  • In the 4th model, I have used BoxCox transformation (with lambda=0.3956) with damped option. In this model the smoothing parameter alpha has highest value amongst the 4 models.
  • Also, 4th model seems to have lowest RMSE and also lowest AIC. So both from minimizing the squared error and maximum likelihood estimation perspective, 4th model seems to perform best.

Section 7.8 Exercise 8

Recall your retail time series data (from Exercise 3 in Section 2.10).

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

Select one of the time series as follows (but replace the column name with your own chosen column):

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

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

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

retailts
##        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:
retail_plot <- autoplot(retailts,ylab="$ Sales Turnover",xlab="Year") + ggtitle(title)

retail_plot

  1. Why is multiplicative seasonality necessary for this series?

Multiplicative Seasonality

Based on the timeseries plot for the retail data set, it can be observed that the seasonal variations are not constant throughout the series. From very narrow seasonal spike patterns observed upto 1990, the seasonal variations seems to gradually increase in more recent years. Due to this pattaren in variation of seasonality, multiplicative seasonality is necessary for this dataset.

  1. Apply Holt-Winters' multiplicative method to the data. Experiment with making the trend damped.

Holt-Winters' Seasonal multiplicative method

hw_fit <- hw(retailts,seasonal="multiplicative")

# Model Fit Summary
summary(hw_fit)
## 
## Forecast method: Holt-Winters' multiplicative method
## 
## Model Information:
## Holt-Winters' multiplicative method 
## 
## Call:
##  hw(y = retailts, seasonal = "multiplicative") 
## 
##   Smoothing parameters:
##     alpha = 0.6698 
##     beta  = 0.001 
##     gamma = 0.3302 
## 
##   Initial states:
##     l = 53.7332 
##     b = -0.2201 
##     s = 1.0771 1.0202 1.0414 2.0211 1.0031 0.8147
##            0.8122 0.7791 0.6602 0.6255 1.138 1.0073
## 
##   sigma:  0.0865
## 
##      AIC     AICc      BIC 
## 4326.553 4328.239 4393.580 
## 
## Error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
## Training set 0.5571551 13.17456 9.918904 0.3439157 5.973236 0.4821535 0.1309425
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 2014       346.7416 308.3194 385.1637 287.9800 405.5031
## Feb 2014       308.5693 267.3562 349.7824 245.5393 371.5993
## Mar 2014       344.5202 291.7880 397.2524 263.8732 425.1672
## Apr 2014       323.5621 268.4193 378.7050 239.2284 407.8958
## May 2014       337.3144 274.4885 400.1403 241.2305 433.3983
## Jun 2014       325.7551 260.3076 391.2026 225.6618 425.8484
## Jul 2014       341.6900 268.3512 415.0288 229.5279 453.8520
## Aug 2014       372.1479 287.4476 456.8482 242.6100 501.6858
## Sep 2014       393.7348 299.2689 488.2008 249.2616 538.2080
## Oct 2014       400.0202 299.3341 500.7062 246.0341 554.0062
## Nov 2014       381.1500 280.9033 481.3966 227.8359 534.4640
## Dec 2014       433.9998 315.1242 552.8754 252.1952 615.8044
## Jan 2015       349.8455 246.0604 453.6307 191.1198 508.5712
## Feb 2015       311.3302 215.9081 406.7523 165.3947 457.2657
## Mar 2015       347.6013 237.7323 457.4702 179.5711 515.6314
## Apr 2015       326.4543 220.2190 432.6897 163.9813 488.9273
## May 2015       340.3281 226.4711 454.1851 166.1988 514.4573
## Jun 2015       328.6640 215.7741 441.5540 156.0137 501.3144
## Jul 2015       344.7398 223.3123 466.1672 159.0325 530.4470
## Aug 2015       375.4679 239.9961 510.9396 168.2817 582.6540
## Sep 2015       397.2457 250.5711 543.9203 172.9262 621.5652
## Oct 2015       403.5853 251.2304 555.9402 170.5786 636.5921
## Nov 2015       384.5453 236.2488 532.8418 157.7453 611.3452
## Dec 2015       437.8640 265.4986 610.2294 174.2539 701.4742
# Plot
autoplot(retailts) +
  autolayer(hw_fit, series="HW multiplicative forecasts",
    PI=FALSE) +
  xlab("Year") +
  ylab("$Sales Turnover") +
  ggtitle("Holt-Winter's Multiplicative Method: Retail Sales for Category = 'A3349337W'") +
  guides(colour=guide_legend(title="Forecast"))

Holt-Winters' Seasonal multiplicative method with Damped=TRUE

hw_damped_fit <- hw(retailts,seasonal="multiplicative", damped=TRUE, phi = 0.98)

# Model Fit Summary
summary(hw_damped_fit)
## 
## Forecast method: Damped Holt-Winters' multiplicative method
## 
## Model Information:
## Damped Holt-Winters' multiplicative method 
## 
## Call:
##  hw(y = retailts, seasonal = "multiplicative", damped = TRUE,  
## 
##  Call:
##      phi = 0.98) 
## 
##   Smoothing parameters:
##     alpha = 0.6724 
##     beta  = 0.002 
##     gamma = 0.3275 
##     phi   = 0.98 
## 
##   Initial states:
##     l = 53.5627 
##     b = 0.9142 
##     s = 1.148 1.0532 1.0646 1.9194 0.9555 0.8506
##            0.7216 0.7618 0.7045 0.7144 1.0987 1.0078
## 
##   sigma:  0.0828
## 
##      AIC     AICc      BIC 
## 4294.810 4296.496 4361.838 
## 
## Error measures:
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set 0.3335282 13.19289 9.969852 0.05283515 6.044622 0.4846301
##                   ACF1
## Training set 0.1439144
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 2014       346.9051 310.0912 383.7190 290.6031 403.2071
## Feb 2014       308.9977 269.4082 348.5872 248.4508 369.5446
## Mar 2014       345.3191 294.5537 396.0844 267.6801 422.9580
## Apr 2014       324.6524 271.4536 377.8513 243.2918 406.0131
## May 2014       338.5508 277.8628 399.2389 245.7365 431.3652
## Jun 2014       326.8392 263.5824 390.0959 230.0963 423.5820
## Jul 2014       342.4905 271.6149 413.3661 234.0957 450.8853
## Aug 2014       372.5448 290.7259 454.3638 247.4135 497.6761
## Sep 2014       393.5366 302.3545 484.7187 254.0856 532.9875
## Oct 2014       399.1711 302.0675 496.2747 250.6639 547.6782
## Nov 2014       379.9981 283.3329 476.6634 232.1614 527.8349
## Dec 2014       432.4982 317.8361 547.1602 257.1377 607.8587
## Jan 2015       348.7325 248.5982 448.8668 195.5903 501.8747
## Feb 2015       310.6021 218.3962 402.8080 169.5854 451.6188
## Mar 2015       347.0866 240.7587 453.4144 184.4721 509.7010
## Apr 2015       326.2907 223.3113 429.2701 168.7973 483.7840
## May 2015       340.2352 229.7719 450.6984 171.2962 509.1741
## Jun 2015       328.4426 218.8928 437.9924 160.9007 495.9845
## Jul 2015       344.1474 226.3637 461.9312 164.0127 524.2821
## Aug 2015       374.3224 243.0122 505.6325 173.5007 575.1440
## Sep 2015       395.3886 253.3676 537.4097 178.1862 612.5911
## Oct 2015       401.0241 253.6657 548.3826 175.6588 626.3895
## Nov 2015       381.7384 238.3618 525.1151 162.4628 601.0141
## Dec 2015       434.4524 267.7957 601.1091 179.5730 689.3318
# Plot
autoplot(retailts) +
  autolayer(hw_damped_fit, series="HW multiplicative forecasts",
    PI=FALSE) +
  xlab("Year") +
  ylab("$Sales Turnover") +
  ggtitle("Holt-Winter's Multiplicative Method (w/ Damped Option): Retail Sales for Category = 'A3349337W'") +
  guides(colour=guide_legend(title="Forecast"))

Making the trend damped didn't seem to make any major impact on the model.

  1. Compare the RMSE of the one-step forecasts from the two methods. Which do you prefer?

RMSE comparison of the two models

# Accuracy of the Model Fit w/o damping
accuracy(hw_fit)
##                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
## Training set 0.5571551 13.17456 9.918904 0.3439157 5.973236 0.4821535 0.1309425
# Accuracy of the Model Fit w/ damping
accuracy(hw_damped_fit)
##                     ME     RMSE      MAE        MPE     MAPE      MASE
## Training set 0.3335282 13.19289 9.969852 0.05283515 6.044622 0.4846301
##                   ACF1
## Training set 0.1439144

I prefer the the model without damping and lower RMSE.

  1. Check that the residuals from the best method look like white noise.

Residual Plot for Best Method:

checkresiduals(hw_fit)

## 
##  Ljung-Box test
## 
## data:  Residuals from Holt-Winters' multiplicative method
## Q* = 143.08, df = 8, p-value < 2.2e-16
## 
## Model df: 16.   Total lags used: 24

Based on above output of Ljung-Box test, the p-value is very small. So it cannot be said that residuals are from White Noise.

  1. Now find the test set RMSE, while training the model to the end of 2010. Can you beat the seasonal naive approach from Exercise 8 in Section 3.7?

Train/Test Split

retail.train <- window(retailts, end=c(2010, 12))
retail.test <- window(retailts, start=c(2011))

autoplot(retailts) +
  autolayer(retail.train, series="Training") +
  autolayer(retail.test, series="Test") +
  ggtitle('Train/Test Split - Retail Data') +
  ylab("$Sales Turnover")

Model Approach

I have used 3 different methods to fit the training set:

  • Seasonal Naive
  • Holt-Winter's Multiplicative Trend
  • Holt-Winter's Additive Trend, with Box-Cox Transform
fit_snaive <- snaive(retail.train, h=36)
fit1_hw <- hw(retail.train, h=36, seasonal='multiplicative', damped=FALSE)

lambda <- BoxCox.lambda(retail.train)
fit2_hw <- hw(retail.train, h=36, seasonal='additive', damped=FALSE, lambda=lambda)

autoplot(retail.test, series='Test Data') +
  autolayer(fit_snaive, series='Seasonal Naive Forecast', PI=F) +
  autolayer(fit1_hw, series="Holt-Winter's Multiplicative Forecast", PI=F) +
  autolayer(fit2_hw, series="Holt-Winter's Additive Forecast + Box Cox", PI=F) +
  guides(colour=guide_legend(title="Legend")) +
  ggtitle('Test Set Forecast') +
  ylab("$Sales Turnover")

Test Set RMSE

df <- data.frame(c('Seasonal Naive Forecast', "Holt-Winter's Multiplicative Method", 
               "Holt-Winter's Additive Method with Box-Cox Transform"), c(accuracy(fit_snaive)[,"RMSE"],accuracy(fit1_hw)[,"RMSE"], accuracy(fit2_hw)[,"RMSE"]))

colnames(df) <- c("Model","RMSE")

df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="250px")
Model RMSE
Seasonal Naive Forecast 26.30758
Holt-Winter's Multiplicative Method 13.33918
Holt-Winter's Additive Method with Box-Cox Transform 14.03422

From the above table, Holt-Winter's Multiplicative Method has the best RMSE beating the snaive model.

Section 7.8 Exercise 9

For the same retail data, try an STL decomposition applied to the Box-Cox transformed series, followed by ETS on the seasonally adjusted data. How does that compare with your best previous forecasts on the test set?

STL Decomposition with Box cox Transform

lambda <- BoxCox.lambda(retail.train)
paste('Optimal value of lambda for Box-Cox Transformation:', lambda)
## [1] "Optimal value of lambda for Box-Cox Transformation: 1.00693651001761"
stl_bc_fit <- stlf(retail.train, lambda = lambda)

# Model Summary
summary(stl_bc_fit)
## 
## Forecast method: STL +  ETS(A,N,N)
## 
## Model Information:
## ETS(A,N,N) 
## 
## Call:
##  ets(y = na.interp(x), model = etsmodel, allow.multiplicative.trend = allow.multiplicative.trend) 
## 
##   Smoothing parameters:
##     alpha = 0.7218 
## 
##   Initial states:
##     l = 68.0462 
## 
##   sigma:  11.1992
## 
##      AIC     AICc      BIC 
## 3686.948 3687.019 3698.479 
## 
## Error measures:
##                    ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set 1.053989 10.76922 7.910296 0.458137 5.013251 0.3725362 0.01781996
## 
## Forecasts:
##          Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
## Jan 2011       325.2653 311.4754 339.0512 304.1738 346.3474
## Feb 2011       300.7595 283.7424 317.7699 274.7313 326.7720
## Mar 2011       321.3420 301.6334 341.0422 291.1968 351.4676
## Apr 2011       309.2123 287.1254 331.2882 275.4287 342.9703
## May 2011       313.4711 289.2450 337.6843 276.4148 350.4970
## Jun 2011       303.8016 277.6023 329.9851 263.7264 343.8399
## Jul 2011       309.2746 281.2491 337.2825 266.4056 352.1024
## Aug 2011       326.3042 296.5729 356.0168 280.8258 371.7386
## Sep 2011       340.8754 309.5311 372.1998 292.9296 388.7744
## Oct 2011       353.3555 320.4772 386.2126 303.0632 403.5981
## Nov 2011       358.4085 324.0607 392.7335 305.8680 410.8955
## Dec 2011       398.1516 362.4189 433.8621 343.4934 452.7577
## Jan 2012       325.2653 288.1200 362.3812 268.4433 382.0183
## Feb 2012       300.7595 262.2801 339.2047 241.8948 359.5438
## Mar 2012       321.3420 281.6129 361.0370 260.5661 382.0378
## Apr 2012       309.2123 268.2420 350.1448 246.5364 371.7995
## May 2012       313.4711 271.3111 355.5917 248.9750 377.8746
## Jun 2012       303.8016 260.4704 347.0897 237.5125 369.9896
## Jul 2012       309.2746 264.8184 353.6864 241.2642 377.1806
## Aug 2012       326.3042 280.7634 371.8008 256.6353 395.8693
## Sep 2012       340.8754 294.2735 387.4331 269.5836 412.0632
## Oct 2012       353.3555 305.7146 400.9518 280.4747 426.1315
## Nov 2012       358.4085 309.7440 407.0271 283.9616 432.7476
## Dec 2012       398.1516 348.5186 447.7417 322.2250 473.9773
autoplot(retail.train, series = "train") +
  autolayer(stl_bc_fit, series = 'STL w/ Box Cox') +
  guides(colour=guide_legend(title="Legend")) +
  ggtitle('STL with Box Cox for Retail Data Set') +
  ylab("$Sales Turnover")

accuracy(stl_bc_fit)
##                    ME     RMSE      MAE      MPE     MAPE      MASE       ACF1
## Training set 1.053989 10.76922 7.910296 0.458137 5.013251 0.3725362 0.01781996

ETS on Seasonally Adjusted data

ets_retail <- ets(seasadj(decompose(retail.train,"multiplicative")))

# Model Summary
summary(ets_retail)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = seasadj(decompose(retail.train, "multiplicative"))) 
## 
##   Smoothing parameters:
##     alpha = 0.5313 
##     beta  = 1e-04 
##     gamma = 0.4659 
## 
##   Initial states:
##     l = 55.7984 
##     b = 1.4509 
##     s = 0.9796 0.9465 1.0616 1.51 1.0368 0.9474
##            0.9034 0.918 0.8875 0.8549 0.9539 1.0004
## 
##   sigma:  0.0751
## 
##      AIC     AICc      BIC 
## 3757.328 3759.200 3822.668 
## 
## Training set error measures:
##                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
## Training set -1.165599 12.34511 9.276026 -1.147755 5.731817 0.4351278 0.2202526
autoplot(retail.train, series = 'Train Set') + 
  autolayer(forecast(ets_retail, h = 24, PI=F), series = "ETS Forecast") +
  guides(colour=guide_legend(title="Legend")) +
  ggtitle('ETS Forecast for Retail Data Set') +
  ylab("$Sales Turnover")

accuracy(ets_retail)
##                     ME     RMSE      MAE       MPE     MAPE      MASE      ACF1
## Training set -1.165599 12.34511 9.276026 -1.147755 5.731817 0.4351278 0.2202526

RMSE Comparison

df1 <- data.frame(c('STL w/ Box Cox Transform', "ETS on Seasonally Adjusted Data"), c(accuracy(stl_bc_fit)[,"RMSE"],accuracy(ets_retail)[,"RMSE"]))

colnames(df1) <- c("Model","RMSE")

df <- rbind(df,df1)


df %>% kable() %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% scroll_box(width="100%",height="300px")
Model RMSE
Seasonal Naive Forecast 26.30758
Holt-Winter's Multiplicative Method 13.33918
Holt-Winter's Additive Method with Box-Cox Transform 14.03422
STL w/ Box Cox Transform 10.76922
ETS on Seasonally Adjusted Data 12.34511

Conclusion

Both the models - STL Decomposition + Box Cox and ETS method on seasonally adjusted data shows lower RMSE than the previous best method.