This is an example of ETS, see the blog for Theory.
International Tourist Visitor nights to Australia
library(fpp2)
## Warning: package 'fpp2' was built under R version 3.6.1
## Loading required package: ggplot2
## Registered S3 methods overwritten by 'ggplot2':
## method from
## [.quosures rlang
## c.quosures rlang
## print.quosures rlang
## Loading required package: forecast
## Warning: package 'forecast' was built under R version 3.6.1
## Registered S3 method overwritten by 'xts':
## method from
## as.zoo.xts zoo
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Registered S3 methods overwritten by 'forecast':
## method from
## fitted.fracdiff fracdiff
## residuals.fracdiff fracdiff
## Loading required package: fma
## Warning: package 'fma' was built under R version 3.6.1
## Loading required package: expsmooth
## Warning: package 'expsmooth' was built under R version 3.6.1
Lets use the function
aust <- window(austourists,start=2005)
fit <- ets(aust)
summary(fit)
## ETS(M,A,M)
##
## Call:
## ets(y = aust)
##
## Smoothing parameters:
## alpha = 0.1908
## beta = 0.0392
## gamma = 2e-04
##
## Initial states:
## l = 32.3679
## b = 0.9281
## s = 1.0218 0.9628 0.7683 1.2471
##
## sigma: 0.0383
##
## AIC AICc BIC
## 224.8628 230.1569 240.9205
##
## Training set error measures:
## ME RMSE MAE MPE MAPE MASE
## Training set 0.04836907 1.670893 1.24954 -0.1845609 2.692849 0.409454
## ACF1
## Training set 0.2005962
The Model selected is MAM Lets plot it
autoplot(fit)
Lets get the residuals and forecast errors
cbind('Residuals' = residuals(fit),
'Forecast errors' = residuals(fit,type='response')) %>%
autoplot(facet=TRUE) + xlab("Year") + ylab("")
Lets Forecast with ETS function
fit %>% forecast(h=8) %>%
autoplot() +
ylab("International visitor night in Australia (millions)")