Exploring forecast
Time series forecasting is interesting. I want to write more, but not right now. I’m just going to lay out a few functions for explanation later.
library(fpp2)
library(purrr)
library(dplyr)
I am going to test a few different methods:
-
Mean forecasting
-
Random Walk (last value is forecast with an addition)
-
Seasonal Naive (last seasons value is next guess)
-
Naive (Previous value is forecast)
beer2 <- window(ausbeer, start= 1992, end = c(2007,4))
beer_fit1 <- meanf(beer2, h=10)
beer_fit2 <- rwf(beer2, h=10)
beer_fit3 <- snaive(beer2, h=10)
beer_fit4 <- naive(beer2, h=10)
Let’s see how we did on the forecast.
beer3 <- window(ausbeer, start =2008)
models <- list(mean_forecast = beer_fit1, rand_walk = beer_fit2, seasonal_naive = beer_fit3,
naive = beer_fit4)
map(models, accuracy, beer3)
$mean_forecast
$ ME RMSE MAE MPE MAPE MASE ACF1 Training set 0.000 43.62858 35.23438 -0.9365102 7.886776 2.463942 -0.10915105 Test set -13.775 38.44724 34.82500 -3.9698659 8.283390 2.435315 -0.06905715 Theil's U Training set NA Test set 0.801254
$rand_walk
$ ME RMSE MAE MPE MAPE MASE Training set 0.4761905 65.31511 54.73016 -0.9162496 12.16415 3.827284 Test set -51.4000000 62.69290 57.40000 -12.9549160 14.18442 4.013986 ACF1 Theil's U Training set -0.24098292 NA Test set -0.06905715 1.254009
$seasonal_naive
$ ME RMSE MAE MPE MAPE MASE ACF1 Training set -2.133333 16.78193 14.3 -0.5537713 3.313685 1.0000000 -0.2876333 Test set 5.200000 14.31084 13.4 1.1475536 3.168503 0.9370629 0.1318407 Theil's U Training set NA Test set 0.298728
$naive
$ ME RMSE MAE MPE MAPE MASE Training set 0.4761905 65.31511 54.73016 -0.9162496 12.16415 3.827284 Test set -51.4000000 62.69290 57.40000 -12.9549160 14.18442 4.013986 ACF1 Theil's U Training set -0.24098292 NA Test set -0.06905715 1.254009
Seasonal Naive looks like it won!
plot(beer_fit3)

Reuse
Citation
@online{dewitt2018,
author = {Michael E. DeWitt},
title = {Exploring forecast},
date = {2018-07-08},
url = {https://michaeldewittjr.com/blog/2018-07-08-exploring-forecast/},
langid = {en}
}
Michael E. DeWitt. July 8, 2018. "Exploring forecast". https://michaeldewittjr.com/blog/2018-07-08-exploring-forecast/.