• Stars
    star
    421
  • Rank 102,977 (Top 3 %)
  • Language
    R
  • License
    Other
  • Created almost 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tools for time series analysis and forecasting

TSstudio

CRAN_Status_Badge Downloads lifecycle License: MIT

The TSstudio package provides a set of tools descriptive and predictive analysis of time series data. That includes utility functions for preprocessing time series data, interactive visualization functions based on the plotly package engine, and set of tools for training and evaluating time series forecasting models from the forecast, forecastHybrid, and bsts packages.

More information available on the package vignettes.

Installation

Install the stable version from CRAN:

install.packages("TSstudio")

or install the development version from Github:

# install.packages("devtools")
devtools::install_github("RamiKrispin/TSstudio")

Usage

Plotting time series data

library(TSstudio)
data(USgas)

# Ploting time series object
ts_plot(USgas, 
        title = "US Monthly Natural Gas Consumption",
        Ytitle = "Billion Cubic Feet")

Seasonality analysis

# Seasonal plot
ts_seasonal(USgas, type = "all")

# Heatmap plot

ts_heatmap(USgas)

Correlation analysis

# ACF and PACF plots
ts_cor(USgas, lag.max = 60)

# Lags plot
ts_lags(USgas, lags = 1:12)

# Seasonal lags plot
ts_lags(USgas, lags = c(12, 24, 36, 48))

Training forecasting models

# Forecasting applications
# Setting training and testing partitions
USgas_s <- ts_split(ts.obj = USgas, sample.out = 12)
train <- USgas_s$train
test <- USgas_s$test

# Forecasting with auto.arima
library(forecast)
md <- auto.arima(train)
fc <- forecast(md, h = 12)

# Plotting actual vs. fitted and forecasted
test_forecast(actual = USgas, forecast.obj = fc, test = test)

# Plotting the forecast 
plot_forecast(fc)

# Run horse race between multiple models
methods <- list(ets1 = list(method = "ets",
                            method_arg = list(opt.crit = "lik"),
                            notes = "ETS model with opt.crit = lik"),
                ets2 = list(method = "ets",
                            method_arg = list(opt.crit = "amse"),
                            notes = "ETS model with opt.crit = amse"),
                arima1 = list(method = "arima",
                              method_arg = list(order = c(2,1,0)),
                              notes = "ARIMA(2,1,0)"),
                arima2 = list(method = "arima",
                              method_arg = list(order = c(2,1,2),
                                                seasonal = list(order = c(1,1,1))),
                              notes = "SARIMA(2,1,2)(1,1,1)"),
                hw = list(method = "HoltWinters",
                          method_arg = NULL,
                          notes = "HoltWinters Model"),
                tslm = list(method = "tslm",
                            method_arg = list(formula = input ~ trend + season),
                            notes = "tslm model with trend and seasonal components"))
# Training the models with backtesting
md <- train_model(input = USgas,
                  methods = methods,
                  train_method = list(partitions = 6, 
                                      sample.out = 12, 
                                      space = 3),
                  horizon = 12,
                  error = "MAPE")
# A tibble: 6 x 7
  model_id model       notes                                         avg_mape avg_rmse `avg_coverage_80%` `avg_coverage_95%`
  <chr>    <chr>       <chr>                                            <dbl>    <dbl>              <dbl>              <dbl>
1 arima2   arima       SARIMA(2,1,2)(1,1,1)                            0.0557     167.              0.583              0.806
2 hw       HoltWinters HoltWinters Model                               0.0563     163.              0.736              0.889
3 ets1     ets         ETS model with opt.crit = lik                   0.0611     172.              0.681              0.903
4 ets2     ets         ETS model with opt.crit = amse                  0.0666     186.              0.458              0.833
5 tslm     tslm        tslm model with trend and seasonal components   0.0767     220.              0.417              0.667
6 arima1   arima       ARIMA(2,1,0)                                    0.188      598.              0.875              0.958
# Plot the performance of the different models on the testing partitions
plot_model(md)

# Holt-Winters tunning parameters with grid search
hw_grid <- ts_grid(USgas, 
                   model = "HoltWinters",
                   periods = 6,
                   window_space = 6,
                   window_test = 12,
                   hyper_params = list(alpha = seq(0,1,0.1),
                                       beta = seq(0,1,0.1),
                                       gamma = seq(0,1,0.1)))
                                       
plot_grid(hw_grid, type = "3D")

More Repositories

1

coronavirus

The coronavirus dataset
HTML
499
star
2

deploy-flex-actions

Deploying flexdashboard on Github Pages with Docker and Github Actions
HTML
185
star
3

awesome-ds-setting

A tutorial for setting a new machine with core data science tools
181
star
4

vscode-python

Setting Python Development Environment with VScode and Docker
145
star
5

atsaf

Applied Time Series Analysis and Forecasting
R
130
star
6

coronavirus_dashboard

The Coronavirus Dashboard
R
105
star
7

shinylive

A guide for deploying Shinylive Python application into Github Pages
HTML
101
star
8

USelectricity

Forecast the US demand for electricity
R
96
star
9

italy_dash

A summary dashboard of the covid19 cases in Italy
Dockerfile
75
star
10

MLstudio

The ML Studio Package
R
70
star
11

covid19Italy

Italy covid19 data
R
46
star
12

coronavirus-csv

CSV format for the coronavirus R package dataset
R
46
star
13

30DayChartChallenge

Code for 30DayChartChallenge
R
34
star
14

UKgrid

The UK National Grid historical demand for electricity
R
28
star
15

30DayMapChallenge

30 Day Map Challenge 2022
R
27
star
16

R-Ladies-Tunis-Docker-Workshop

R-Ladies Tunis Docker for R users workshop
Dockerfile
24
star
17

uselectricity-etl

Example for ETL process with R, Docker, and Github Actions (WIP...).
R
24
star
18

USgrid

The hourly demand and supply of electricity in the US
R
23
star
19

Introduction-to-JavaScript

Introduction to JavaScript - math operations, variables, functions, objects, etc.
TeX
16
star
20

uswildfire

US Wildfire Dashboard
Shell
15
star
21

gis-dataviz-workshop

Materials for R-Ladies Abuja geospatial visualization workshop
HTML
14
star
22

sfo

Monthly air passengers and landings at San Francisco International Airport (SFO)
R
13
star
23

Time-Series-Workshop

Bay Area useR Group Time Series Workshop
HTML
13
star
24

covid19sf

R package for tracking Covid19 cases in San Francisco
R
12
star
25

RamiKrispin

My README profile
9
star
26

Shiny-App

A shiny interface for ML models, data visualization etc.
R
8
star
27

USgas

Tracking US monthly consumption of natural gas
R
7
star
28

ai-dev-2024-ml-workshop

Materials for the AI Dev 2024 "Deploy and Monitor ML Pipelines with Open Source and Free Applications" workshop
Shell
7
star
29

halloween-time-series-workshop

Bay Area useR Group Halloween Time Series Workshop
HTML
7
star
30

shinylive-r

A guide for deploying Shinylive R application into Github Pages
6
star
31

EIAapi

Supporting tools for the Applied Time Series Analysis and Forecasting book
R
6
star
32

flexdashboard_example

An example for deployment of flexdashboard
5
star
33

Julia-tutorials

Julia's learning materials
Julia
2
star
34

forecastML

Time series forecasting with linear regression and machine learning methods
R
2
star
35

learningR

Learning R
2
star
36

visualization_final

2
star
37

rstudio-conf-ggplot2-workshop

Setting Docker environment for the Graphic Design with ggplot2 workshop at RStudio conf 2022
R
2
star
38

covid19-US

Dashboard to track the covid19 pandemic in the US
1
star
39

covid19wiki

Collections of covid19 tables sourced from Wiki pages
R
1
star
40

covid19county

R
1
star
41

math_expressions

Example of using mathematical expressions in a README file
1
star
42

docker

My Docker files
Shell
1
star
43

RamiKrispin.github.io

My blog
HTML
1
star
44

piecewise-regression

An Introduction to Piecewise Regression with Time Series
R
1
star
45

linkedin-dashboard

Example of LinkedIn Profile Engagement Dashboard
R
1
star
46

TStrain

Approaches and methods for training forecasting models
HTML
1
star
47

shiny-express-poc

Running Shiny Express App Inside a Container
JavaScript
1
star
48

rstudio-conf-2020-geospatial

This repo contains the materials from the geospatial training.
1
star
49

ts-cluster-analysis-r

Materials for the the Analyzing Time Series at Scale with Cluster Analysis in R Workshop
R
1
star