Extending broom for time series forecasting
Extending
broomto time series forecasting
The
sweeppackage extends the
broomtools (tidy, glance, and augment) for performing forecasts and time series analysis in the “tidyverse”. The package is geared towards “tidying” the forecast workflow used with Rob Hyndman’s
forecastpackage.
tidyversetools in R for Data Science
broomfor model analysis (ARIMA, ETS, BATS, etc)
forecastobjects for easy plotting and “tidy” data manipulation
timetkto enable dates and datetimes (irregular time series) in the tidied forecast output
The package contains the following elements:
model tidiers:
sw_tidy,
sw_glance,
sw_augment,
sw_tidy_decompfunctions extend
tidy,
glance, and
augmentfrom the
broompackage specifically for models (
ets(),
Arima(),
bats(), etc) used for forecasting.
forecast tidier:
sw_sweepconverts a
forecastobject to a tibble that can be easily manipulated in the “tidyverse”.
sweepenables converting a
forecastobject to
tibble. The result is ability to use
dplyr,
tidyr, and
ggplotnatively to manipulate, analyze and visualize forecasts.
Often forecasts are required on grouped data to analyse trends in sub-categories. The good news is scaling from one time series to many is easy with the various
sw_functions in combination with
dplyrand
purrr.
A common goal in forecasting is to compare different forecast models against each other.
sweephelps in this area as well.
If you are familiar with
broom, you know how useful it is for retrieving “tidy” format model components.
sweepextends this benefit to the
forecastpackage workflow with the following functions:
sw_tidy: Returns model coefficients (single column)
sw_glance: Returns accuracy statistics (single row)
sw_augment: Returns residuals
sw_tidy_decomp: Returns seasonal decompositions
sw_sweep: Returns tidy forecast outputs.
The compatibility chart is listed below.
| Object | sw_tidy() | sw_glance() | sw_augment() | sw_tidy_decomp() | sw_sweep() | | :---------- | :--------: | :----------: | :-----------: | :----------------: | :---------: | | ar | | | | | | | arima | X | X | X | | | | Arima | X | X | X | | | | ets | X | X | X | X | | | robets | X | X | X | X | | | baggedETS | | | | | | | bats | X | X | X | X | | | tbats | X | X | X | X | | | nnetar | X | X | X | | | | stl | | | | X | | | HoltWinters | X | X | X | X | | | StructTS | X | X | X | X | | | tslm | X | X | X | | | | decompose | | | | X | | | adf.test | X | X | | | | | Box.test | X | X | | | | | kpss.test | X | X | | | | | forecast | | | | | X |
Function Compatibility
Here’s how to get started.
Development version with latest features:
# install.packages("devtools") devtools::install_github("business-science/sweep")
The
sweeppackage includes several vignettes to help users get up to speed quickly:
sweep