Exploring forecast

Let’s examine some of the functions inside for forecast

timeseries
forecasting
r
Author
Affiliation
Published

July 7, 2018

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)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
── Attaching packages ────────────────────────────────────────────── fpp2 2.4 ──
✓ ggplot2   3.3.5.9000     ✓ fma       2.4       
✓ forecast  8.16           ✓ expsmooth 2.3       
library(purrr)
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

I am going to test a few different methods:

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

BibTeX citation:
@online{dewitt2018,
  author = {Michael DeWitt},
  title = {Exploring Forecast},
  date = {2018-07-07},
  url = {https://michaeldewittjr.com/programming/2018-07-08-exploring-forecast},
  langid = {en}
}
For attribution, please cite this work as:
Michael DeWitt. 2018. “Exploring Forecast.” July 7, 2018. https://michaeldewittjr.com/programming/2018-07-08-exploring-forecast.