This will be a continuation of the ETS model in a previous discussion where I brought in Restaurant Sales and Drinking Places data from the U.S. Census. Again, this is an interesting data series since we use it a lot for work in the food commodities context, particularly during the initial stages of the pandemic until now.
I will attempt to use neural networks to forecast this data series. In the previous discussion, it looks like an ARIMA or an ETS model could perform better, but for the sake of the exercise, I will do it with ANN too.
#load restaurant and Drinking Places, NSA (Non-Seasonally Adjusted)--trying to get seasonality in
rest <-read.csv("RSFSDPN.csv")
rest_ts<-rest[,2]
rest_ts<-ts(rest_ts,start=c(2007,1),frequency=12)
autoplot(rest_ts) +
geom_smooth(formula = y ~ x, method = "loess", color = "orange", size = 0.3) +
labs(title = "Restaruant Sales"
,x = "Date"
,y = "Million USD$") +
theme_ipsum_es()
At first it looks like due to COVID, it could be very hard to predict the correction. still, the NNA model provided ok results when plotted. Although it was going to be almost impossible to predict the fall in COVID, it was interesting to see what the trend was going to be in the recovery and after.
train<-window(rest_ts,end=c(2018,6))
test<-window(rest_ts,start=c(2022,1))
train.fit<-nnetar(train)
autoplot(forecast(train.fit,h=72))+
autolayer(rest_ts) +
theme_ipsum_es() +
labs(y = "sales in millions"
, title = "Restaurant Sales, Forecast NNAR(1,1,2)")+
scale_y_continuous(labels = scales::dollar)
From the difference in both models, it doesnt look like there is much to be changed since seasonality appears to be strong. The trend looks realistic in the test area, since it was impossible to predict the fall due to COVID. The subsequent recovery appears to be in line with what both models suggest could be in the future.
# train<-window(rest_ts,end=c(2018,6))
# test<-window(rest_ts,start=c(2022,3))
train.arima <-auto.arima(train)
autoplot(forecast(train.arima, h=72))+
autolayer(rest_ts) +
theme_ipsum_es() +
labs(y = "sales in millions"
#, title = "Restaurant Sales, Forecast NNAR(1,1,2)"
)+
scale_y_continuous(labels = scales::dollar)
the ARIMA model had better results, but I would need to investigate the NNA further.
#table with results
knitr::kable(accuracy(train.arima),"html")
| ME | RMSE | MAE | MPE | MAPE | MASE | ACF1 | |
|---|---|---|---|---|---|---|---|
| Training set | 60.94679 | 729.4719 | 557.1819 | 0.1022242 | 1.197565 | 0.2510564 | -0.0157698 |
knitr::kable(accuracy(train.fit), "html")
| ME | RMSE | MAE | MPE | MAPE | MASE | ACF1 | |
|---|---|---|---|---|---|---|---|
| Training set | 0.5583975 | 981.1616 | 787.8264 | -0.0496833 | 1.751155 | 0.3549808 | 0.3296572 |