-
Notifications
You must be signed in to change notification settings - Fork 31
/
README.Rmd
145 lines (100 loc) · 5.17 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
message = F,
warning = F,
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
```{r, echo=FALSE}
library(tidyquant)
library(sweep)
```
# sweep <img src="man/figures/logo.png" width="147" height="170" align="right" />
> Extending `broom` to time series forecasting
<!-- badges: start -->
[![R-CMD-check](https://github.com/business-science/sweep/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/business-science/sweep/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/business-science/sweep/branch/master/graph/badge.svg)](https://app.codecov.io/gh/business-science/sweep)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/sweep)](https://cran.r-project.org/package=sweep)
![](http://cranlogs.r-pkg.org/badges/sweep?color=brightgreen)
![](http://cranlogs.r-pkg.org/badges/grand-total/sweep?color=brightgreen)
<!-- badges: end -->
The `sweep` package extends the `broom` tools (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 `forecast` package.
## Benefits
* __Designed for modeling and scaling forecasts using the the `tidyverse` tools in [_R for Data Science_](https://r4ds.hadley.nz/)__
* __Extends `broom` for model analysis (ARIMA, ETS, BATS, etc)__
* __Tidies the `forecast` objects for easy plotting and "tidy" data manipulation__
* __Integrates `timetk` to enable dates and datetimes (irregular time series) in the tidied forecast output__
## Tools
The package contains the following elements:
1. __model tidiers__: `sw_tidy`, `sw_glance`, `sw_augment`, `sw_tidy_decomp` functions extend `tidy`, `glance`, and `augment` from the `broom` package specifically for models (`ets()`, `Arima()`, `bats()`, etc) used for forecasting.
2. __forecast tidier__: `sw_sweep` converts a `forecast` object to a tibble that can be easily manipulated in the "tidyverse".
## Making forecasts in the tidyverse
`sweep` enables converting a `forecast` object to `tibble`. The result is ability to use `dplyr`, `tidyr`, and `ggplot` natively to manipulate, analyze and visualize forecasts.
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics("man/figures/forecast.png")
```
## Forecasting multiple time series groups at scale
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 `dplyr` and `purrr`.
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics("man/figures/time_series_groups.png")
```
## Forecasting multiple models for accuracy
A common goal in forecasting is to compare different forecast models against each other. `sweep` helps in this area as well.
```{r echo=FALSE, out.width='100%'}
knitr::include_graphics("man/figures/multiple_models.png")
```
## broom extensions for forecasting
If you are familiar with `broom`, you know how useful it is for retrieving "tidy" format model components. `sweep` extends this benefit to the `forecast` package 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.
```{r, echo = F}
tibble::tribble(
~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", "",
"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"
) %>%
knitr::kable(caption = "Function Compatibility",
align = c("l", "c", "c", "c", "c", "c"))
```
## Installation
Here's how to get started.
Development version with latest features:
``` {r, eval = FALSE}
# install.packages("remotes")
remotes::install_github("business-science/sweep")
```
<!-- CRAN approved version: -->
<!-- ```{r, eval = FALSE} -->
<!-- install.packages("sweep") -->
<!-- ``` -->
## Further Information
The `sweep` package includes several vignettes to help users get up to speed quickly:
* SW00 - Introduction to `sweep`
* SW01 - Forecasting Time Series Groups in the tidyverse
* SW02 - Forecasting Using Multiple Models
<!-- See the [`tidyquant` vignettes](https://cran.r-project.org/package=tidyquant) for further details on the package. -->