Skip to content
Feature Extraction And Statistics for Time Series
R
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R Set minimum feat_stl acf lag to 10 Sep 13, 2019
hex Added hex stickers May 24, 2019
man Update README for CRAN installation Aug 28, 2019
tests Avoid dependence on x13binary for supported platform check Aug 30, 2019
vignettes Fix URL in vignette Aug 6, 2019
.Rbuildignore Added cran-comments Jul 13, 2019
.gitignore Added first pass of feasts vignette (code, no explanation) Aug 2, 2019
.travis.yml Set minimum R version to 3.5.0 due to usage of isFALSE Jul 10, 2019
DESCRIPTION Increment version number Sep 12, 2019
NAMESPACE Fix guerrero imports Aug 27, 2019
NEWS.md Fixed versioning of NEWS Sep 12, 2019
README.Rmd Fixed link to CRAN package Aug 29, 2019
README.md Fixed link to CRAN package Aug 29, 2019
_pkgdown.yml Updated pkgdown news for v0.1.0 release Sep 12, 2019
appveyor.yml
codecov.yml Added codecov May 23, 2019
cran-comments.md Update cran-comments Sep 1, 2019
feasts.Rproj Updated .Rproj name Feb 8, 2019
tic.R Use dev pkgdown Aug 26, 2019

README.md

feasts

Travis build status AppVeyor Build Status Coverage status CRAN_Status_Badge Lifecycle: experimental

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 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 package.

Installation

You could install the stable version from CRAN:

install.packages("feasts")

You can install the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("tidyverts/feasts")

Usage

library(feasts)
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 to produce customisable graphics to visualise time series patterns.

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
aus_production %>% STL(Beer ~ season(window = Inf))
#> # A dable:           218 x 6 [1Q]
#> # STL Decomposition: Beer = trend + season_year + remainder
#>    Quarter  Beer trend season_year remainder season_adjust
#>      <qtr> <dbl> <dbl>       <dbl>     <dbl>         <dbl>
#>  1 1956 Q1   284  272.        2.14     10.1           282.
#>  2 1956 Q2   213  264.      -42.6      -8.56          256.
#>  3 1956 Q3   227  258.      -28.5      -2.34          255.
#>  4 1956 Q4   308  253.       69.0     -14.4           239.
#>  5 1957 Q1   262  257.        2.14      2.55          260.
#>  6 1957 Q2   228  261.      -42.6       9.47          271.
#>  7 1957 Q3   236  263.      -28.5       1.80          264.
#>  8 1957 Q4   320  264.       69.0     -12.7           251.
#>  9 1958 Q1   272  266.        2.14      4.32          270.
#> 10 1958 Q2   233  266.      -42.6       9.72          276.
#> # … with 208 more rows
aus_production %>% STL(Beer ~ season(window = Inf)) %>% 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.

aus_retail %>%
  features(Turnover, feat_stl)
#> # A tibble: 152 x 9
#>    State Industry trend_strength seasonal_streng… spikiness linearity curvature seasonal_peak_y…
#>    <chr> <chr>             <dbl>            <dbl>     <dbl>     <dbl>     <dbl>            <dbl>
#>  1 Aust… Cafes, …          0.989            0.537   6.15e-5     227.      48.6                 0
#>  2 Aust… Cafes, …          0.993            0.610   1.12e-4     342.      77.9                 0
#>  3 Aust… Clothin…          0.990            0.918   4.77e-6     131.      17.4                 9
#>  4 Aust… Clothin…          0.992            0.952   2.06e-5     195.      19.4                 9
#>  5 Aust… Departm…          0.975            0.977   2.79e-5     130.     -43.9                 9
#>  6 Aust… Electri…          0.991            0.929   3.03e-5     233.      -9.08                9
#>  7 Aust… Food re…          0.999            0.882   2.74e-4    1264.     199.                  9
#>  8 Aust… Footwea…          0.980            0.937   5.54e-6      64.0      1.98                9
#>  9 Aust… Furnitu…          0.980            0.669   4.66e-5     141.     -21.6                 9
#> 10 Aust… Hardwar…          0.992            0.895   1.47e-5     173.      45.2                 9
#> # … with 142 more rows, and 1 more variable: seasonal_trough_year <dbl>

This allows you to visualise the behaviour of many time series (where the plotting methods above would show too much information).

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.

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")

You can’t perform that action at this time.