-
Notifications
You must be signed in to change notification settings - Fork 23
/
README.Rmd
125 lines (94 loc) · 4.12 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(width = 100)
```
# feasts <a href='https://feasts.tidyverts.org'><img src='man/figures/logo.png' align="right" height="138.5" /></a>
<!-- badges: start -->
[![R build status](https://github.com/tidyverts/feasts/workflows/R-CMD-check/badge.svg)](https://github.com/tidyverts/feasts/actions?workflow=R-CMD-check)
[![Coverage status](https://codecov.io/gh/tidyverts/feasts/branch/master/graph/badge.svg)](https://app.codecov.io/gh/tidyverts/feasts?branch=master)
[![CRAN status](https://www.r-pkg.org/badges/version/feasts)](https://CRAN.R-project.org/package=feasts)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html)
<!-- badges: end -->
## Overview
feasts provides a collection of tools for the analysis of time series data. The package name is an acronym comprising of its key features: *Feature Extraction And Statistics for Time Series*.
The package works with tidy temporal data provided by the [tsibble](https://github.com/tidyverts/tsibble) package to produce time series features, decompositions, statistical summaries and convenient visualisations. These features are useful in understanding the behaviour of time series data, and closely integrates with the tidy forecasting workflow used in the [fable](https://github.com/tidyverts/fable) package.
## Installation
You could install the **stable** version from [CRAN](https://cran.r-project.org/package=feasts):
```{r, eval = FALSE}
install.packages("feasts")
```
You can install the **development** version from
[GitHub](https://github.com/tidyverts/feasts) with:
```{r gh-installation, eval = FALSE}
# install.packages("remotes")
remotes::install_github("tidyverts/feasts")
```
## Usage
```{r pkgs, message = FALSE, warning = FALSE}
library(feasts)
library(tsibble)
library(tsibbledata)
library(dplyr)
library(ggplot2)
library(lubridate)
```
### Graphics
Visualisation is often the first step in understanding the patterns in time series data. The package uses [ggplot2](https://github.com/tidyverse/ggplot2) to produce customisable graphics to visualise time series patterns.
```{r graphics, fig.height=3}
aus_production %>% gg_season(Beer)
aus_production %>% gg_subseries(Beer)
aus_production %>% filter(year(Quarter) > 1991) %>% gg_lag(Beer)
aus_production %>% ACF(Beer) %>% autoplot()
```
### Decompositions
A common task in time series analysis is decomposing a time series into some simpler components. The feasts package supports two common time series decomposition methods:
* Classical decomposition
* STL decomposition
<!--
* X11 decomposition
* X-13ARIMA-SEATS decomposition
-->
```{r dcmp}
dcmp <- aus_production %>%
model(STL(Beer ~ season(window = Inf)))
components(dcmp)
```
```{r dcmp-plot}
components(dcmp) %>% autoplot()
```
### Feature extraction and statistics
Extract features and statistics across a large collection of time series to identify unusual/extreme time series, or find clusters of similar behaviour.
```{r features}
aus_retail %>%
features(Turnover, feat_stl)
```
This allows you to visualise the behaviour of many time series (where the plotting methods above would show too much information).
```{r features-plot}
aus_retail %>%
features(Turnover, feat_stl) %>%
ggplot(aes(x = trend_strength, y = seasonal_strength_year)) +
geom_point() +
facet_wrap(vars(State))
```
Most of Australian's retail industries are highly trended and seasonal for all states.
It's also easy to extract the most (and least) seasonal time series.
```{r extreme}
extreme_seasonalities <- aus_retail %>%
features(Turnover, feat_stl) %>%
filter(seasonal_strength_year %in% range(seasonal_strength_year))
aus_retail %>%
right_join(extreme_seasonalities, by = c("State", "Industry")) %>%
ggplot(aes(x = Month, y = Turnover)) +
geom_line() +
facet_grid(vars(State, Industry, scales::percent(seasonal_strength_year)),
scales = "free_y")
```