DATA 624—Homework No. 2

Ben Horvath

February 16, 2020

Problem No. 3.1

For the following series, find an appropriate Box-Cox transformation in order to stabilise the variance: usnetelec usgdp mcopper enplanements

For each dataset: Calculate the optimal \(\lambda\) and plot the original and transformed data set side by side. Be sure to compare the range of the y-axes.

Problem No. 3.2

Why is a Box-Cox transformation unhelpful for the cangas data?

The problem is in the excess seasonal variation in the 1980s. Box-Cox is unable to ‘smooth’ that out, and so fails in its goal to make subsequent modeling simpler.

## [1] 0.5767759

Problem No. 3.3

What Box-Cox transformation would you select for your retail data (from Exercise 3 in Section 2.10)?

Load the data and select a particular time series:

Find the appropriate \(\lambda\) and plot:

## [1] 0.1116205

Problem No. 3.8

For your retail time series:

  1. Split the data into two parts.

Since I have 31 years of monthly data, I will set the test data to the last 6 years (about 20 percent): 2008 through 2013.

  1. Check that your data have been split appropriately by producing the following plot.

Looks good, not sure what that black line is:

  1. Calculate forecasts using snaive applied to train.
  1. Compare the accuracy of your forecasts against the actual values stored in test.

The main result of accuracy() is that the forecast performs worse on the test set than the train set. This is expected. Depending on our application, this forecast could still be useful, or it could be too far off the mark for us to use.

##                   ME     RMSE      MAE      MPE     MAPE     MASE
## Training set  8.6633 13.57660 10.54680 5.222720 6.585582 1.000000
## Test set     22.7125 28.46872 24.50417 7.361669 8.022287 2.323374
##                    ACF1 Theil's U
## Training set  0.1750858        NA
## Test set     -0.1281384  0.370597

A plot of the forecast shows it is reasonable to the eye:

  1. Check the residuals. Do the residuals appear to be uncorrelated and normally distributed?

## 
##  Ljung-Box test
## 
## data:  Residuals from Seasonal naive method
## Q* = 270.61, df = 24, p-value < 2.2e-16
## 
## Model df: 0.   Total lags used: 24

The histogram of the residuals looks approximately normal—right tail is perhaps too long.

The residuals by time plot looks fairly good, except 2003–5, where the residuals are consistently positive. We would probably want to investigate that. Otherwise, it looks like they have a mean around zero.

The ACF plot is problematic. The first twelve months are highly highly (and significantly) correlated. We can also the Ljung-Box test has a large \(Q*\), suggesting the autocorrelation is not due to random noise.

  1. How sensitive are the accuracy measures to the training/test split?

It’s probably not advisable to split data right where the U.S. economy was about to crash, in late 2007, especially for retail data.

We could write a for loop to evaluate predictions across multiple division points and get a good idea of how sensitive the models are to train/test split.