knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

fable.tbats

R-CMD-check Codecov test coverage Lifecycle: stable CRAN status

fable.tbats is a wrapper around the implementation of tbats originally from the forecast package, though it now works without this dependency.

Installation

pak::pkg_install("JSzitas/fable.tbats")

Usage

Used just like any model in fable:

library(tsibbledata)
library(fable)
library(fable.tbats)
library(dplyr)

# fit models to the pelt dataset until 1930:
train <- pelt %>% 
  filter(Year < 1930)
test <- pelt %>% 
  filter(Year >= 1930)

models <- train %>% 
  model( ets = ETS(Lynx),
         bats = BATS(Lynx),
         tbats = TBATS(Lynx)
         ) 
# generate forecasts on the test set
forecasts <- forecast(models, test)
# visualize
autoplot(forecasts, pelt)

Similarly, accuracy calculation works:

train_accuracies <- accuracy(models)
knitr::kable(train_accuracies)
test_accuracies <- accuracy(forecasts, test)
knitr::kable(test_accuracies)

As does refitting:

models <- refit( models, pelt )

Of the functionality available in the forecast package, only forecast::tbats.components() is missing.

Performance note

Fitting bats/tbats to a few long series can (potentially) be slower using this wrapper than using the forecast package. This is due to the fact that the internal tbats/bats algorithm always executes sequentially (i.e. with use.parallel = FALSE ) to prevent issues with nested parallelism (as the fabletools::model function is taken to be responsible for handling parallelization).

This should never be a problem on many time series, but does lead to a significant slow-down if you are only modelling a single/few time series. Nonetheless, in those cases the fasster package might be much better suited for your use case anyways.



JSzitas/fable.tbats documentation built on April 18, 2023, 1:55 a.m.