Today, give a try to Techtonique web app, a tool designed to help you make informed, datadriven decisions using Mathematics, Statistics, Machine Learning, and Data Visualization
Two weeks ago I presented ahead
, an R package for univariate and multivariate time series forecasting. And last week, I’ve shown how
ahead::dynrmf
could be used for automatic univariate forecasting.
This week, I compare the speeds of execution of ahead::ridge2f
(quasirandomized autoregressive network) and ahead::varf
(Vector AutoRegressive model), with their default parameters (notably 1 lag, and 5stepsahead forecasting). For more examples of multivariate time series forecasting with ahead
, you can type ?ahead::ridge2f
, ?ahead::varf(x)
, or ?ahead::plot.mtsforecast
in R console, once the package is installed and loaded.
Here’s how to install ahead
:

1st method: from Runiverse
In R console:
options(repos = c( techtonique = 'https://techtonique.runiverse.dev', CRAN = 'https://cloud.rproject.org')) install.packages("ahead")

2nd method: from Github
In R console:
devtools::install_github("Techtonique/ahead")
Or
remotes::install_github("Techtonique/ahead")
Loading packages for the demo:
library(ahead)
library(microbenchmark)
Benchmarks:
With 10 time series and 10000 observations:
x < ts(matrix(rnorm(100000), ncol = 10))
(res < microbenchmark::microbenchmark(ahead::ridge2f(x), ahead::varf(x), times = 10L))
Unit: milliseconds
expr min lq mean median uq max neval
ahead::ridge2f(x) 28.74215 32.22568 48.10457 35.70773 39.54476 104.5946 10
ahead::varf(x) 126.64908 138.91396 171.74475 157.16234 207.46105 237.5916 10
ggplot2::autoplot(res)
With 100 time series and 1000 observations:
x < ts(matrix(rnorm(100000), ncol = 100))
(res < microbenchmark::microbenchmark(ahead::ridge2f(x), ahead::varf(x), times = 10L))
Unit: milliseconds
expr min lq mean median uq max neval
ahead::ridge2f(x) 46.8317 48.44567 81.1854 53.52305 61.06889 220.5755 10
ahead::varf(x) 2276.9425 2293.05932 2360.1591 2316.90078 2362.63500 2696.0487 10
ggplot2::autoplot(res)
With 1000 time series and 100 observations:
x < ts(matrix(rnorm(100000), ncol = 1000))
(res < microbenchmark::microbenchmark(ahead::ridge2f(x), ahead::varf(x), times = 10L))
Unit: seconds
expr min lq mean median uq max neval
ahead::ridge2f(x) 1.891717 2.18807 2.315703 2.253376 2.286887 3.048088 10
ahead::varf(x) 226.133743 234.94063 240.931083 239.235557 247.780707 259.656456 10
ggplot2::autoplot(res)
ahead::ridge2f
is fast and scalable, mostly because I implemented some of its parts in C++, via Rcpp
. In addition, the algorithm is mainly made of matrices products and inversions – with the inversions being the most expensive parts, according to profvis::profvis
.
If you are interested in making the algorithm even faster in a GitHub fork, notice that: the most training time is spent at lines 267–275 of this file, which corresponds to section 2.3 of the paper.
sessionInfo()
R version 4.0.4 (20210215)
Platform: x86_64appledarwin17.0 (64bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] fr_FR.UTF8/fr_FR.UTF8/fr_FR.UTF8/C/fr_FR.UTF8/fr_FR.UTF8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bigtime_0.2.1
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 urca_1.30 compiler_4.0.4 pillar_1.4.6 iterators_1.0.13
[6] vars_1.53 tools_4.0.4 digest_0.6.25 corrplot_0.84 ahead_0.2.0
[11] lifecycle_0.2.0 tibble_3.0.3 gtable_0.3.0 nlme_3.1152 lattice_0.2041
[16] pkgconfig_2.0.3 rlang_0.4.10 foreach_1.5.1 rstudioapi_0.11 microbenchmark_1.47
[21] dplyr_1.0.2 generics_0.0.2 vctrs_0.3.4 tidyselect_1.1.0 lmtest_0.938
[26] grid_4.0.4 glue_1.4.2 R6_2.5.0 randtoolbox_1.30.1 fpp_0.5
[31] farver_2.0.3 purrr_0.3.4 ggplot2_3.3.3 magrittr_1.5 scales_1.1.1
[36] codetools_0.218 ellipsis_0.3.1 MASS_7.353 strucchange_1.52 colorspace_1.41
[41] sandwich_3.00 rngWELL_0.106 munsell_0.5.0 crayon_1.3.4 zoo_1.88
Comments powered by Talkyard.