Forescasting Principles and Practice (Hyndman & Athanasopoulos)

Exercise 7.1

Consider the pigs series — the number of pigs slaughtered in Victoria each month. a. Use the ses() function in R to find the optimal values of α and ℓ0, and generate forecasts for the next four months. b. Compute a 95% prediction interval for the first forecast using y ± 1.96s where s is the standard deviation of the residuals. Compare your interval with the interval produced by R.

##  Time-Series [1:188] from 1980 to 1996: 76378 71947 33873 96428 105084 ...
##         Jan    Feb    Mar    Apr    May    Jun
## 1980  76378  71947  33873  96428 105084  95741
## 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
##      95% 
## 119020.8
##      95% 
## 78611.97
## [1] 118952.8
## [1] 78679.97

Exercise 7.5

Data set books contains the daily sales of paperback and hardcover books at the same store. The task is to forecast the next four days’ sales for paperback and hardcover books. a. Plot the series and discuss the main features of the data. b. Use the ses() function to forecast each series, and plot the forecasts. c. Compute the RMSE values for the training data in each case.

##  Time-Series [1:30, 1:2] from 1 to 30: 199 172 111 209 161 119 195 195 131 183 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:2] "Paperback" "Hardcover"
## Time Series:
## Start = 1 
## End = 6 
## Frequency = 1 
##   Paperback Hardcover
## 1       199       139
## 2       172       128
## 3       111       172
## 4       209       139
## 5       161       191
## 6       119       168
## [1] 1

c) RMSE for hardcover is smaller than paperback by almost 2 points

Exercise 7.6

We will continue with the daily sales of paperback and hardcover books in data set books. a. Apply Holt’s linear method to the paperback and hardback series and compute four-day forecasts in each case. b. 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. c. Compare the forecasts for the two series using both methods. Which do you think is best? d. 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.

## [1] 31.13692
## [1] 27.19358
##      95% 
## 275.0205
##     95% 
## 143.913
##      95% 
## 275.3523
##     95% 
## 138.867
##      95% 
## 307.4256
##      95% 
## 192.9222
##      95% 
## 304.3403
##      95% 
## 174.7799
b) RMSE’s for Holt’s method are lower for both series (Paperback and Hardcover) than SES by at least 2+ points.
c) Holt’s method seems to provide a better forecast as it shows a more consistent upward trend in the future as opposed to SES which looks completely flat
d) 95% prediction intervals fro Holt method are slightly higher than SES

Exercise 7.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?

##  Time-Series [1:94] from 1900 to 1993: 277 315 315 321 315 ...
## Time Series:
## Start = 1900 
## End = 1905 
## Frequency = 1 
## [1] 276.79 315.42 314.87 321.25 314.54 317.92

## [1] 26.58219
## [1] 26.54019
## [1] 1.032217
## [1] 1.039187
The best model seems to be the Holt with Box Cox transformation which gives the lowest RAMSE (1.032217). It is followed very closely by the Holt Damped with Box Cox transformation (RMSE of 1.039187)

Exercise 7.8

Recall your retail time series data (from Exercise 3 in Section 2.10). a. Why is multiplicative seasonality necessary for this series? b. Apply Holt-Winters’ multiplicative method to the data. Experiment with making the trend damped. c. Compare the RMSE of the one-step forecasts from the two methods. Which do you prefer? d. Check that the residuals from the best method look like white noise. e. Now find the test set RMSE, while training the model to the end of 2010. Can you beat the seasonal naïve approach from Exercise 8 in Section 3.7?

a) Because the time series shows seasonal variation that increases with the level of the series, therefore, multiplicative model is more appropriate

## [1] 14.72762
## [1] 14.94306

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

##                       ME      RMSE       MAE          MPE      MAPE
## Training set  0.03021223  9.107356  6.553533  0.001995484  3.293399
## Test set     78.34068365 94.806617 78.340684 19.945024968 19.945025
##                   MASE       ACF1 Theil's U
## Training set 0.4107058 0.02752875        NA
## Test set     4.9095618 0.52802701  1.613903
c) RMSE’s are very similar, but the damped ones is a little higher, so I think the best is the one not damped
d) Residuals for the best method look like white noise as per ACF graph
e) Seasonal Naive approach has a better RMSE than HW, 71.44 vs 94.80

Exercise 7.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?

## Warning in InvBoxCox(fcast$mean, lambda, biasadj, fcast): biasadj
## information not found, defaulting to FALSE.

##                      ME      RMSE       MAE        MPE      MAPE      MASE
## Training set -0.6782982  8.583559  5.918078 -0.3254076  2.913104 0.3708823
## Test set     82.1015276 98.384220 82.101528 21.0189982 21.018998 5.1452516
##                    ACF1 Theil's U
## Training set 0.02704667        NA
## Test set     0.52161725  1.679783