Pick a time series of interest to you. Build an auto.arima model as well as an ETS model. Which performed better? Now hold out 6 months of data for a test set and try to forecast using the ETS and the auto.arima. Which performs better on the hold-out set?
Imports = read.csv("/Users/austin/Desktop/Graduate\ School\ /Boston\ College/Spring\ Semster\ 2021/Predictive\ Analytics/Discussions/Week\ 4/EXPCH.csv") %>%
mutate(DATE = ymd(DATE)) %>%
filter(DATE < ymd("2021-02-01")) %>%
filter(DATE > ymd("2010-12-01"))
#as.numeric(Imports$EXPCH)
head(Imports)
## DATE EXPCH
## 1 2011-01-01 8017.792
## 2 2011-02-01 8383.310
## 3 2011-03-01 9563.728
## 4 2011-04-01 8000.503
## 5 2011-05-01 7849.159
## 6 2011-06-01 7867.005
Imports.ts = ts(Imports$EXPCH, start = 2011, frequency = 12)
Imports.train = ts(Imports.ts[1:115], start = 2011, frequency = 12)
Imports.test = ts(Imports.ts[116:121], start = 2020.5, frequency = 12) # 6 month test set
#ARIMA
ARIMA.model = auto.arima(Imports.train)
ARIMA.forecast = forecast(ARIMA.model, h = 6)
summary(ARIMA.model)
## Series: Imports.train
## ARIMA(0,1,1)(0,1,1)[12]
##
## Coefficients:
## ma1 sma1
## -0.2875 -0.7159
## s.e. 0.0973 0.1409
##
## sigma^2 estimated as 604128: log likelihood=-826.95
## AIC=1659.9 AICc=1660.15 BIC=1667.78
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set -19.81989 724.7955 496.6665 -0.3896673 5.146455 0.5007264
## ACF1
## Training set 0.005638876
ARIMA.accuracy = accuracy(ARIMA.forecast, Imports.test)
print(ARIMA.accuracy)
## ME RMSE MAE MPE MAPE MASE
## Training set -19.81989 724.7955 496.6665 -0.3896673 5.146455 0.5007264
## Test set 3679.27024 3862.8063 3679.2702 26.5823447 26.582345 3.7093455
## ACF1 Theil's U
## Training set 0.005638876 NA
## Test set -0.419705262 2.110051
#Graph the results
autoplot(Imports.ts) +
autolayer(ARIMA.forecast, series = "ARIMA Forecast") +
autolayer(Imports.test, series = "Actual Imports")
#ETS
ETS.model = ets(Imports.train)
ETS.forecast = forecast(ETS.model, h = 6)
summary(ETS.model)
## ETS(M,N,M)
##
## Call:
## ets(y = Imports.train)
##
## Smoothing parameters:
## alpha = 0.8594
## gamma = 1e-04
##
## Initial states:
## l = 9455.5427
## s = 1.1217 1.1511 1.166 0.9638 0.9618 0.9329
## 0.9479 0.9418 0.9365 1.0465 0.914 0.916
##
## sigma: 0.0717
##
## AIC AICc BIC
## 2062.032 2066.881 2103.206
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE ACF1
## Training set 2.972101 654.6038 476.6547 -0.2338417 4.97959 0.480551 -0.1065196
ETS.accuracy = accuracy(ETS.forecast, Imports.test)
print(ETS.accuracy)
## ME RMSE MAE MPE MAPE MASE
## Training set 2.972101 654.6038 476.6547 -0.2338417 4.97959 0.480551
## Test set 3180.108227 3404.4948 3180.1082 22.9904996 22.99050 3.206103
## ACF1 Theil's U
## Training set -0.1065196 NA
## Test set -0.4430810 1.886946
#Graph the results
autoplot(Imports.ts) +
autolayer(ETS.forecast, series = "ETS Forecast") +
autolayer(Imports.test, series = "Actual Imports")
#Graph the results
autoplot(Imports.ts) +
autolayer(ARIMA.forecast, series = "ARIMA Forecast") +
autolayer(ETS.forecast, series = "ETS Forecast") +
autolayer(Imports.test, series = "Actual Imports")