Lab Session 8

retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
mytimeseries <- ts(retaildata[["A3349873A"]],
                  frequency=12, start=c(1982,4))
fit <- ets(mytimeseries)
summary(fit)
## ETS(M,A,M) 
## 
## Call:
##  ets(y = mytimeseries) 
## 
##   Smoothing parameters:
##     alpha = 0.5067 
##     beta  = 1e-04 
##     gamma = 0.3222 
## 
##   Initial states:
##     l = 63.0202 
##     b = 0.7934 
##     s=0.9391 0.912 0.9294 1.5281 1.0577 0.9868
##            0.9604 0.941 0.9431 0.901 0.9661 0.9353
## 
##   sigma:  0.0488
## 
##      AIC     AICc      BIC 
## 4018.808 4020.494 4085.835 
## 
## Training set error measures:
##                     ME    RMSE     MAE         MPE     MAPE      MASE
## Training set 0.1576127 13.5932 8.70378 -0.09176148 3.711149 0.4596804
##                     ACF1
## Training set 0.008030422
autoplot(forecast(fit))

x1 <- window(mytimeseries, end=c(2010,12))
x2 <- window(mytimeseries, start=2011)
f1 <- snaive(x1, h=length(x2))
f2 <- hw(x1, h=length(x2), seasonal='multi')
f3 <- forecast(ets(x1), h=length(x2))
accuracy(f1,x2)
##                     ME      RMSE      MAE       MPE      MAPE     MASE
## Training set  7.772973  20.24576 15.95676  4.702754  8.109777 1.000000
## Test set     81.744444 100.00869 82.06667 20.549055 20.669738 5.143067
##                   ACF1 Theil's U
## Training set 0.7385090        NA
## Test set     0.6830879   1.67023
accuracy(f2,x2)
##                      ME      RMSE       MAE        MPE     MAPE      MASE
## Training set  0.2335309  8.817788  6.393003  0.1048658  3.20614 0.4006455
## Test set     78.8187005 95.779065 78.818701 20.0382885 20.03829 4.9395188
##                    ACF1 Theil's U
## Training set 0.06611033        NA
## Test set     0.52771581  1.630125
accuracy(f3,x2)
##                      ME       RMSE       MAE        MPE      MAPE
## Training set  0.3404863   8.784116  6.289258  0.1876561  3.128791
## Test set     95.8058083 113.202964 95.805808 24.5580948 24.558095
##                   MASE       ACF1 Theil's U
## Training set 0.3941439 0.01203982        NA
## Test set     6.0040903 0.61158849  1.922081
bicoal %>% ets %>% forecast %>% autoplot

chicken %>% ets %>% forecast %>% autoplot

dole %>% ets %>% forecast %>% autoplot

usdeaths %>% ets %>% forecast %>% autoplot