Learn R Programming

⚠️There's a newer version (2.9.0) of this package.Take me there.

timetk

Time series analysis in the tidyverse

Installation

Download the development version with latest features:

remotes::install_github("business-science/timetk")

Or, download CRAN approved version:

install.packages("timetk")

Package Functionality

There are many R packages for working with Time Series data. Here’s how timetk compares to the “tidy” time series R packages for data visualization, wrangling, and feature engineeering (those that leverage data frames or tibbles).

Tasktimetktsibblefeaststibbletime
Structure
Data Structuretibble (tbl)tsibble (tbl_ts)tsibble (tbl_ts)tibbletime (tbl_time)
Visualization
Interactive Plots (plotly):x::x::x:
Static Plots (ggplot):x::x:
Time Series:x::x:
Correlation, Seasonality:x::x:
Data Wrangling
Time-Based Summarization:x::x:
Time-Based Filtering:x::x:
Padding Gaps:x::x:
Low to High Frequency:x::x::x:
Imputation:x::x:
Sliding / Rolling:x:
Machine Learning
Time Series Machine Learning:x::x::x:
Anomaly Detection:x::x::x:
Clustering:x::x::x:
Feature Engineering (recipes)
Date Feature Engineering:x::x::x:
Holiday Feature Engineering:x::x::x:
Fourier Series:x::x::x:
Smoothing & Rolling:x::x::x:
Padding:x::x::x:
Imputation:x::x::x:
Cross Validation (rsample)
Time Series Cross Validation:x::x::x:
Time Series CV Plan Visualization:x::x::x:
More Awesomeness
Making Time Series (Intelligently):x:
Handling Holidays & Weekends:x::x::x:
Class Conversion:x::x:
Automatic Frequency & Trend:x::x::x:

Getting Started

Summary

Timetk is an amazing package that is part of the modeltime ecosystem for time series analysis and forecasting. The forecasting system is extensive, and it can take a long time to learn:

  • Many algorithms
  • Ensembling and Resampling
  • Machine Learning
  • Deep Learning
  • Scalable Modeling: 10,000+ time series

Your probably thinking how am I ever going to learn time series forecasting. Here’s the solution that will save you years of struggling.

Take the High-Performance Forecasting Course

Become the forecasting expert for your organization

High-Performance Time Series Course

Time Series is Changing

Time series is changing. Businesses now need 10,000+ time series forecasts every day. This is what I call a High-Performance Time Series Forecasting System (HPTSF) - Accurate, Robust, and Scalable Forecasting.

High-Performance Forecasting Systems will save companies by improving accuracy and scalability. Imagine what will happen to your career if you can provide your organization a “High-Performance Time Series Forecasting System” (HPTSF System).

How to Learn High-Performance Time Series Forecasting

I teach how to build a HPTFS System in my High-Performance Time Series Forecasting Course. You will learn:

  • Time Series Machine Learning (cutting-edge) with Modeltime - 30+ Models (Prophet, ARIMA, XGBoost, Random Forest, & many more)
  • Deep Learning with GluonTS (Competition Winners)
  • Time Series Preprocessing, Noise Reduction, & Anomaly Detection
  • Feature engineering using lagged variables & external regressors
  • Hyperparameter Tuning
  • Time series cross-validation
  • Ensembling Multiple Machine Learning & Univariate Modeling Techniques (Competition Winner)
  • Scalable Forecasting - Forecast 1000+ time series in parallel
  • and more.

Acknowledgements

The timetk package wouldn’t be possible without other amazing time series packages.

  • stats - Basically every timetk function that uses a period (frequency) argument owes it to ts().
    • plot_acf_diagnostics(): Leverages stats::acf(), stats::pacf() & stats::ccf()
    • plot_stl_diagnostics(): Leverages stats::stl()
  • lubridate: timetk makes heavy use of floor_date(), ceiling_date(), and duration() for “time-based phrases”.
    • Add and Subtract Time (%+time% & %-time%): "2012-01-01" %+time% "1 month 4 days" uses lubridate to intelligently offset the day
  • xts: Used to calculate periodicity and fast lag automation.
  • forecast (retired): Possibly my favorite R package of all time. It’s based on ts, and it’s predecessor is the tidyverts (fable, tsibble, feasts, and fabletools).
    • The ts_impute_vec() function for low-level vectorized imputation using STL + Linear Interpolation uses na.interp() under the hood.
    • The ts_clean_vec() function for low-level vectorized imputation using STL + Linear Interpolation uses tsclean() under the hood.
    • Box Cox transformation auto_lambda() uses BoxCox.Lambda().
  • tibbletime (retired): While timetk does not import tibbletime, it uses much of the innovative functionality to interpret time-based phrases:
    • tk_make_timeseries() - Extends seq.Date() and seq.POSIXt() using a simple phase like “2012-02” to populate the entire time series from start to finish in February 2012.
    • filter_by_time(), between_time() - Uses innovative endpoint detection from phrases like “2012”
    • slidify() is basically rollify() using slider (see below).
  • slider: A powerful R package that provides a purrr-syntax for complex rolling (sliding) calculations.
    • slidify() uses slider::pslide under the hood.
    • slidify_vec() uses slider::slide_vec() for simple vectorized rolls (slides).
  • padr: Used for padding time series from low frequency to high frequency and filling in gaps.
    • The pad_by_time() function is a wrapper for padr::pad().
    • See the step_ts_pad() to apply padding as a preprocessing recipe!
  • TSstudio: This is the best interactive time series visualization tool out there. It leverages the ts system, which is the same system the forecast R package uses. A ton of inspiration for visuals came from using TSstudio.

Copy Link

Version

Install

install.packages('timetk')

Monthly Downloads

42,179

Version

2.8.1

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

May 31st, 2022

Functions in timetk (2.8.1)

filter_period

Apply filtering expressions inside periods (windows)
box_cox_vec

Box Cox Transformation
future_frame

Make future time series from existing
between_time

Between (For Time Series): Range detection for date or date-time sequences
is_date_class

Check if an object is a date class
fourier_vec

Fourier Series
condense_period

Convert the Period to a Lower Periodicity (e.g. Go from Daily to Monthly)
diff_vec

Differencing Transformation
bike_sharing_daily

Daily Bike Sharing Data
filter_by_time

Filter (for Time-Series Data)
mutate_by_time

Mutate (for Time Series Data)
log_interval_vec

Log-Interval Transformation for Constrained Interval Forecasting
lag_vec

Lag Transformation
normalize_vec

Normalize to Range (0, 1)
m4_hourly

Sample of 4 Hourly Time Series Datasets from the M4 Competition
m4_daily

Sample of 4 Daily Time Series Datasets from the M4 Competition
m4_monthly

Sample of 4 Monthly Time Series Datasets from the M4 Competition
m4_quarterly

Sample of 4 Quarterly Time Series Datasets from the M4 Competition
plot_stl_diagnostics

Visualize STL Decomposition Features for One or More Time Series
parse_date2

Fast, flexible date and datetime parsing
plot_seasonal_diagnostics

Visualize Multiple Seasonality Features for One or More Time Series
pad_by_time

Insert time series rows with regularly spaced timestamps
plot_acf_diagnostics

Visualize the ACF, PACF, and CCFs for One or More Time Series
plot_anomaly_diagnostics

Visualize Anomalies for One or More Time Series
plot_time_series_regression

Visualize a Time Series Linear Regression Formula
m4_yearly

Sample of 4 Yearly Time Series Datasets from the M4 Competition
plot_time_series_cv_plan

Visualize a Time Series Resample Plan
m4_weekly

Sample of 4 Weekly Time Series Datasets from the M4 Competition
plot_time_series

Interactive Plotting for One or More Time Series
plot_time_series_boxplot

Interactive Time Series Box Plots
slidify

Create a rolling (sliding) version of any function
slidify_vec

Rolling Window Transformation
required_pkgs.step_box_cox

S3 methods for tracking which additional packages are needed for steps.
step_diff

Create a differenced predictor
step_box_cox

Box-Cox Transformation using Forecast Methods
smooth_vec

Smoothing Transformation using Loess
standardize_vec

Standardize to Mean 0, Standard Deviation 1 (Center & Scale)
step_holiday_signature

Holiday Feature (Signature) Generator
step_fourier

Fourier Features for Modeling Seasonality
slice_period

Apply slice inside periods (windows)
step_ts_pad

Pad: Add rows to fill gaps and go from low to high frequency
step_ts_clean

Clean Outliers and Missing Data for Time Series
taylor_30_min

Half-hourly electricity demand
step_slidify

Slidify Rolling Window Transformation
step_timeseries_signature

Time Series Feature (Signature) Generator
step_ts_impute

Missing Data Imputation for Time Series
step_log_interval

Log Interval Transformation for Constrained Interval Forecasting
summarise_by_time

Summarise (for Time Series Data)
step_slidify_augment

Slidify Rolling Window Transformation (Augmented Version)
step_smooth

Smoothing Transformation using Loess
time_series_cv

Time Series Cross Validation
time_series_split

Simple Training/Test Set Splitting for Time Series
tk_anomaly_diagnostics

Automatic group-wise Anomaly Detection by STL Decomposition
timetk

timetk: Time Series Analysis in the Tidyverse
tk_acf_diagnostics

Group-wise ACF, PACF, and CCF Data Preparation
tk_get_timeseries_unit_frequency

Get the timeseries unit frequency for the primary time scales
tk_augment_differences

Add many differenced columns to the data
tk_get_timeseries_variables

Get date or datetime variables (column names)
tk_get_timeseries

Get date features from a time-series index
tk_get_holiday

Get holiday features from a time-series index
tk_augment_fourier

Add many fourier series to the data
tk_augment_timeseries

Add many time series features to the data
tk_augment_holiday

Add many holiday features to the data
tk_get_frequency

Automatic frequency and trend calculation from a time series index
tk_make_future_timeseries

Make future time series from existing
time_arithmetic

Add / Subtract (For Time Series)
tk_index

Extract an index of date or datetime from time series objects, models, forecasts
tidyeval

Tidy eval helpers
tk_augment_lags

Add many lags to the data
tk_augment_slidify

Add many rolling window calculations to the data
tk_seasonal_diagnostics

Group-wise Seasonality Data Preparation
tk_stl_diagnostics

Group-wise STL Decomposition (Season, Trend, Remainder)
tk_make_holiday_sequence

Make daily Holiday and Weekend date sequences
set_tk_time_scale_template

Get and modify the Time Scale Template
tk_tbl

Coerce time-series objects to tibble.
tk_summary_diagnostics

Group-wise Time Series Summary
tk_make_timeseries

Intelligent date and date-time sequence creation
tk_xts

Coerce time series objects and tibbles with date/date-time columns to xts.
ts_impute_vec

Missing Value Imputation for Time Series
tk_tsfeatures

Time series feature matrix (Tidy)
tk_time_series_cv_plan

Time Series Resample Plan Data Preparation
walmart_sales_weekly

Sample Time Series Retail Data from the Walmart Recruiting Store Sales Forecasting Competition
tk_ts_dispatch_

S3 methods for ts method dispatch
tk_ts

Coerce time series objects and tibbles with date/date-time columns to ts.
wikipedia_traffic_daily

Sample Daily Time Series Data from the Web Traffic Forecasting (Wikipedia) Competition
tk_zooreg

Coerce time series objects and tibbles with date/date-time columns to ts.
tk_zoo

Coerce time series objects and tibbles with date/date-time columns to xts.
tk_zooreg_dispatch_

S3 methods for zooreg method dispatch
ts_clean_vec

Replace Outliers & Missing Values in a Time Series