CUNY DATA624 Homework 5

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 \(\alpha\) and \(\ell_0\), and generate forecasts for the next four months.

From the below output, we can see that the optimal values are: \(\alpha\) = 0.2971 \(\ell_0\) = 77260.0561

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

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

The table below compares the calculation of the prediction interval “Base R” generated versus the prediction interval from the ses() function. They are slightly different and I’ll admit that I’m unclear why, but Hyndman says that this is due to how the variance is calculated and that R takes into account the degrees of freedom properly.

Lower Upper
Base R 78679.97 118952.8
SES 78611.97 119020.8

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.

Plotted together with the default autoplot function, the graph looks a bit busy, so I split them out. Both hardcover and paperback sales have a clear upward trend. There doesn’t appear to be any seasonality in either trend. Though, it seems tempting to say that there might be a seasonal behavior to paperback sales where a significant rise/fall in sales occurs every 2-3 days, but it’s difficult to definitively say that there is without more data.

c) Compute the RMSE values for the training data in each case.

The ses() function from earlier had calculated the RMSE values for us below.

## [1] "Paperback training -- RMSE: 33.637686782912"
## [1] "Hardcover training -- RMSE: 31.9310149844547"

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.

Paperback Hardcover
ses_RMSE 33.63769 31.93101
holt_RMSE 31.13692 27.19358

We can see that there’s been a reduction in the RMSE using the holt method over using the ses method. This is because the data is trended, so the holt method is the better choice.

c) Compare the forecasts for the two series using both methods. Which do you think is best?

As mentioned in the answer to the previous question, the holt method is the better choice because it takes the trend into account for the forecast.

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

Lower Upper
Base R 141.1798 273.0395
SES 138.8670 275.3523
Lower Upper
Base R 176.9753 302.1449
SES 174.7799 304.3403
Lower Upper
Base R 148.4384 270.4951
Holt 143.9130 275.0205
Lower Upper
Base R 196.8745 303.4733
Holt 192.9222 307.4256

As before, the values are slightly different and I would imagine the reasoning to be the same as in question 1.

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. Which model gives the best RMSE?

From a quick look at the data, there’s a clear downward trend in egg price. We also notice a significant dip around the great depression. There is no obvious seasonality or cyclic behavior.

Below, we play around with the holt function and the lowest I could get the RMSE was below simply from a trial and error approach (not recommended haha).

## [1] "RMSE value: 26.3634693983866"

However, as suggested, we can attempt a BoxCox transformation of the timeseries and we get the below.

When we calculate the RMSE for this, we get a far lower RMSE value:

## [1] "RMSE value: 1.0320000444973"

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

a) Why is multiplicative seasonality necessary for this series?

Because the variation of the seasonality increases over time, a multiplicative approach would be best.

b) Apply Holt-Winters’ multiplicative method to the data. Experiment with making the trend damped.

From the below analysis of damped vs non-damped trend, it appears that the better fit is a non-damped trend.

##                    ME     RMSE      MAE       MPE     MAPE     MASE       ACF1
## Training set 4.244765 29.63087 22.26018 0.2959731 1.785469 0.292681 -0.2184672

##                    ME     RMSE      MAE       MPE     MAPE      MASE       ACF1
## Training set 1.496135 29.43051 22.25676 0.1603693 1.799731 0.2926361 -0.0300701

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

The previous question had already addressed the differences between the two and again, the non-damped method is a better fit.

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

According to the ACF plot above, this series does not 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?

Shown below, the Holt-Winters’ multiplicative method beats out the seasonal naïve approach by quite a bit.

##                     ME      RMSE       MAE      MPE     MAPE     MASE      ACF1
## Training set  73.94114  88.31208  75.13514 6.068915 6.134838 1.000000 0.6312891
## Test set     115.00000 127.92727 115.00000 4.459712 4.459712 1.530576 0.2653013
##              Theil's U
## Training set        NA
## Test set     0.7267171
##                      ME     RMSE      MAE        MPE     MAPE      MASE
## Training set   2.594132 29.87520 22.43516  0.2383033 1.864671 0.2985975
## Test set     -29.588194 49.09806 38.39804 -1.1062616 1.458304 0.5110531
##                     ACF1 Theil's U
## Training set -0.03687893        NA
## Test set      0.09931874  0.267754

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?

First, let’s apply the BoxCox transformation to our retail data.

Nowe we’ll apply STL decomposition on the transformed data.

From here, we now seasonally adjust the data and apply the ETS method.

##                         ME       RMSE        MAE          MPE      MAPE
## Training set -0.0000370996 0.05420367 0.04224946  0.002387178 0.3840713
## Test set     -0.0790652742 0.16610888 0.14222642 -0.611307316 1.0740427
##                   MASE        ACF1 Theil's U
## Training set 0.2807380 -0.14673102        NA
## Test set     0.9450621  0.01879428  1.005492

The RMSE is significantly improved with this method: RMSE=0.16610888 Compare that with the Holt-Winters method multiplicative method where the RMSE for the test set was 49.09806

Chester Poon

2/28/2020