(usnetelec_lb <- BoxCox.lambda(usnetelec))
## [1] 0.5167714
autoplot(BoxCox(usnetelec,usnetelec_lb))
(usgdp_lb <- BoxCox.lambda(usgdp))
## [1] 0.366352
autoplot(BoxCox(usgdp,usgdp_lb))
(mcopper_lb <- BoxCox.lambda(mcopper))
## [1] 0.1919047
autoplot(BoxCox(mcopper,mcopper_lb))
(enplanements_lb <- BoxCox.lambda(enplanements))
## [1] -0.2269461
autoplot(BoxCox(enplanements,enplanements_lb))
(cangas_lb <- BoxCox.lambda(cangas))
## [1] 0.5767759
autoplot(BoxCox(cangas,cangas_lb))
autoplot(cangas)
retaildata <- read_excel('retail.xlsx', skip=1)
myts <- ts(retaildata[,"A3349640L"],frequency=12, start=c(1982,4))
(myts_lb <- BoxCox.lambda(myts))
## [1] 0.1311965
autoplot(BoxCox(myts,myts_lb))
autoplot(myts)
forecast1 <- rwf(myts, drift =TRUE, lambda = myts_lb, h=50, level=80)
forecast2 <- rwf(myts, drift =TRUE, lambda = myts_lb, h=50, level=80, biasadj = TRUE)
## Warning in `/.default`(0.5 * fvar * (1 - lambda), (out)^(2 * lambda)): Recycling array of length 1 in array-vector arithmetic is deprecated.
## Use c() or as.vector() instead.
autoplot(myts) +
autolayer(forecast1, series= 'Simple Back Transformation') +
autolayer(forecast2, series= 'Bias Adjusted', PI=FALSE) +
guides(color =guide_legend(title = 'Model Forecast'))
myts.train <- window(myts, end=c(2010,12))
myts.test <- window(myts, start=2011)
autoplot(myts) +
autolayer(myts.train, series="Training") +
autolayer(myts.test, series="Test")
##### c. Calculate forecasts using snaive applied to myts.train.
fc <- snaive(myts.train)
accuracy(fc,myts.test)
## ME RMSE MAE MPE MAPE MASE
## Training set 13.10781 29.87236 20.66937 7.478844 11.485020 1.000000
## Test set -28.33750 36.99343 29.92083 -7.630292 8.058562 1.447593
## ACF1 Theil's U
## Training set 0.8224883 NA
## Test set 0.4432892 1.292012
Do the residuals appear to be uncorrelated and normally distributed?
checkresiduals(fc)
##
## Ljung-Box test
##
## data: Residuals from Seasonal naive method
## Q* = 1011.9, df = 24, p-value < 2.2e-16
##
## Model df: 0. Total lags used: 24
mean1 <- meanf(myts.train,h=50)
forecast1 <- rwf(myts.train, h=50)
forecast2 <- rwf(myts.train, drift =TRUE, h=50)
autoplot(myts.train) +
autolayer(mean1, series="Mean") +
autolayer(forecast1, series="Naive")+
autolayer(forecast2, series = "Drift")+
guides(colors=guide_legend(title = "Forecasts"))