Lab Session 1
retaildata <- readxl::read_excel("retail.xlsx", skip = 1)
mytimeseries <- ts(retaildata[["A3349873A"]],
frequency=12, start=c(1982,4))
autoplot(mytimeseries)

Lab Session 2
ggseasonplot(mytimeseries)

ggsubseriesplot(mytimeseries)

ggAcf(mytimeseries)

ggAcf(mytimeseries, plot=FALSE)
##
## Autocorrelations of series 'mytimeseries', by lag
##
## 0 1 2 3 4 5 6 7 8 9 10 11
## 1.000 0.862 0.794 0.778 0.757 0.746 0.722 0.727 0.719 0.723 0.718 0.756
## 12 13 14 15 16 17 18 19 20 21 22 23
## 0.858 0.726 0.669 0.656 0.635 0.625 0.604 0.611 0.607 0.614 0.613 0.652
## 24 25
## 0.746 0.622
Lab Session 3
fc <- snaive(mytimeseries, h=36)
autoplot(fc)

checkresiduals(fc)

##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 804.66, df = 24, p-value < 2.2e-16
##
## Model df: 0. Total lags used: 24
Lab Session 4
x1 <- window(mytimeseries, end=c(2010,12))
x2 <- window(mytimeseries, start=2011)
autoplot(cbind(Training=x1,Test=x2))

f1 <- snaive(x1, h=length(x2))
autoplot(f1) + autolayer(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
checkresiduals(f1)

##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 624.45, df = 24, p-value < 2.2e-16
##
## Model df: 0. Total lags used: 24
Lab Session 5
fit <- stl(bricksq, s.window=11)
autoplot(fit)

sa <- seasadj(fit)
autoplot(sa)

sa %>% naive %>% autoplot

fc <- stlf(bricksq, s.window=11, method='naive')
autoplot(fc)

checkresiduals(fc)

fc2 <- stlf(bricksq, s.window=11, method='naive', robust=TRUE)
autoplot(fc2)

checkresiduals(fc2)

Lab Session 6
fc1 <- ses(eggs, h=100)
fc2 <- holt(eggs, h=100)
fc3 <- holt(eggs, damped=TRUE, h=100)
accuracy(fc1)
## ME RMSE MAE MPE MAPE MASE
## Training set -2.740577 26.56395 19.38201 -2.872947 10.05647 0.9560856
## ACF1
## Training set -0.005978463
accuracy(fc2)
## ME RMSE MAE MPE MAPE MASE
## Training set -0.2517656 26.50294 19.16922 -1.334809 9.684965 0.9455886
## ACF1
## Training set 0.007078776
accuracy(fc3)
## ME RMSE MAE MPE MAPE MASE
## Training set -3.092257 26.66198 19.51158 -3.023266 10.11049 0.9624771
## ACF1
## Training set -0.005832122
checkresiduals(fc2)

##
## Ljung-Box test
##
## data: Residuals from Holt's method
## Q* = 10.917, df = 6, p-value = 0.09099
##
## Model df: 4. Total lags used: 10
Lab Session 7
fc <- hw(mytimeseries, seasonal='mult')
fc2 <- hw(mytimeseries,seasonal='mult', damped=TRUE)
accuracy(fc)
## ME RMSE MAE MPE MAPE MASE
## Training set 0.3951082 13.29904 9.065566 0.04520419 3.985358 0.4787877
## ACF1
## Training set 0.05983264
accuracy(fc2)
## ME RMSE MAE MPE MAPE MASE
## Training set 1.125248 13.29399 9.033645 0.4403615 3.951052 0.4771018
## ACF1
## Training set 0.03988704
checkresiduals(fc)

##
## Ljung-Box test
##
## data: Residuals from Holt-Winters' multiplicative method
## Q* = 40.245, df = 8, p-value = 2.884e-06
##
## Model df: 16. Total lags used: 24
f2 <- hw(x1)
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.2822232 12.41601 9.120797 0.2356857 5.234204 0.5715947
## Test set 55.8240257 71.03586 55.824026 15.1866013 15.186601 3.4984569
## ACF1 Theil's U
## Training set 0.1908807 NA
## Test set 0.4544934 1.311197