Lab Session 13

retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
mytimeseries <- ts(retaildata[["A3349873A"]],
                  frequency=12, start=c(1982,4))
(etsmod <- ets(mytimeseries))
## 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
myfn <- function(y,h)
{
  y %>% ets(model="MAM", damped=FALSE) %>% forecast(h=h)
}
e <- tsCV(mytimeseries, myfn)
sqrt(mean(e^2, na.rm=TRUE))
## [1] 15.63519
ggtsdisplay(e)
## Warning: Removed 1 rows containing missing values (geom_point).

myfn <- function(y,h)
{
  y %>% ets %>% forecast(h=h)
}
e2 <- tsCV(mytimeseries, myfn)
sqrt(mean(e2^2, na.rm=TRUE))
## [1] 16.17141
ggtsdisplay(e2)
## Warning: Removed 1 rows containing missing values (geom_point).

Lab Session 14

lambda <- BoxCox.lambda(mytimeseries)
fit1 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 1),
          seasonal=FALSE, lambda=lambda)
fit2 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 2),
          seasonal=FALSE, lambda=lambda)
fit3 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 3),
          seasonal=FALSE, lambda=lambda)
fit4 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 4),
          seasonal=FALSE, lambda=lambda)
fit5 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 5),
          seasonal=FALSE, lambda=lambda)
fit6 <- auto.arima(mytimeseries,
          xreg=fourier(mytimeseries, 6),
          seasonal=FALSE, lambda=lambda)
fit1$aicc
## [1] -29.77232
fit2$aicc
## [1] -157.1155
fit3$aicc
## [1] -303.7034
fit4$aicc
## [1] -551.1655
fit5$aicc
## [1] -571.5915
fit6$aicc
## [1] -639.1607
checkresiduals(fit6)