ahead is a package for univariate and multivariate time series forecasting. Five forecasting methods are implemented so far, as of October 13th, 2021.

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Here's how to install the package:

And here are the packages that will be used in this vignette:

library(ahead)
library(fpp)
library(datasets)
library(randomForest)
library(e1071)
library(ahead)
library(fpp)
library(datasets)
library(randomForest)
library(e1071)

Univariate time series

In this section, we illustrate dynrmf forecasting, with Random Forest and SVM. Do not hesitate to type ?dynrmf, ?armagarchf or ?eatf in R console for more details and examples.

# Plotting forecasts
# With a Random Forest regressor, an horizon of 20, 
# and a 95% prediction interval
plot(dynrmf(fdeaths, h=20, level=95, fit_func = randomForest::randomForest,
      fit_params = list(ntree = 50), predict_func = predict))

# With a Support Vector Machine regressor, an horizon of 20, 
# and a 95% prediction interval
plot(dynrmf(fdeaths, h=20, level=95, fit_func = e1071::svm,
fit_params = list(kernel = "linear"), predict_func = predict))

plot(dynrmf(Nile, h=20, level=95, fit_func = randomForest::randomForest,
      fit_params = list(ntree = 50), predict_func = predict))

plot(dynrmf(Nile, h=20, level=95, fit_func = e1071::svm,
fit_params = list(kernel = "linear"), predict_func = predict))

For more advanced examples on dynrmf, you can read this blog post.

Multivariate time series

In this section, we illustrate ridge2f and varf forecasting. Do not hesitate to type ?ridge2f or ?varf in R console for more details on both functions.

# Forecast using ridge2
# With 2 time series lags, an horizon of 10, 
# and a 95% prediction interval
 fit_obj_ridge2 <- ahead::ridge2f(fpp::insurance, lags = 2,
                                  h = 10, level = 95)


# Forecast using VAR
 fit_obj_VAR <- ahead::varf(fpp::insurance, lags = 2,
                            h = 10, level = 95)


# Plotting forecasts 
# fpp::insurance contains 2 time series, Quotes and TV.advert 
 plot(fit_obj_ridge2, "Quotes")
 plot(fit_obj_VAR, "Quotes")
 plot(fit_obj_ridge2, "TV.advert")
 plot(fit_obj_VAR, "TV.advert")


Techtonique/ahead documentation built on Nov. 24, 2024, 10:33 a.m.