Learn R Programming

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

healthyR.ts

The goal of healthyR.ts is to provide a consistent verb framework for performing time series analysis and forecasting on both administrative and clinical hospital data.

Installation

You can install the released version of healthyR.ts from CRAN with:

install.packages("healthyR.ts")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("spsanderson/healthyR.ts")

Example

This is a basic example which shows you how to generate random walk data.

library(healthyR.ts)
library(ggplot2)

df <- ts_random_walk()

head(df)
#> # A tibble: 6 × 4
#>     run     x        y cum_y
#>   <dbl> <dbl>    <dbl> <dbl>
#> 1     1     1  0.0541  1054.
#> 2     1     2 -0.143    904.
#> 3     1     3 -0.0285   878.
#> 4     1     4  0.245   1093.
#> 5     1     5  0.0658  1165.
#> 6     1     6  0.00266 1168.

Now that the data has been generated, lets take a look at it.

df %>%
   ggplot(
       mapping = aes(
           x = x
           , y = cum_y
           , color = factor(run)
           , group = factor(run)
        )
    ) +
    geom_line(alpha = 0.8) +
    ts_random_walk_ggplot_layers(df)

That is still pretty noisy, so lets see this in a different way. Lets clear this up a bit to make it easier to see the full range of the possible volatility of the random walks.

library(dplyr)
library(ggplot2)

df %>%
    group_by(x) %>%
    summarise(
        min_y = min(cum_y),
        max_y = max(cum_y)
    ) %>%
    ggplot(
        aes(x = x)
    ) +
    geom_line(aes(y = max_y), color = "steelblue") +
    geom_line(aes(y = min_y), color = "firebrick") +
    geom_ribbon(aes(ymin = min_y, ymax = max_y), alpha = 0.2) +
    ts_random_walk_ggplot_layers(df)

This package comes with a wide variety of functions from Data Generators to Statistics functions. The function ts_random_walk() in the above example is a Data Generator.

Let’s take a look at a plotting function.

data_tbl <- data.frame(
  date_col = seq.Date(
    from = as.Date("2020-01-01"),
    to   = as.Date("2022-06-01"),
    length.out = 365*2 + 180
    ),
  value = rnorm(365*2+180, mean = 100)
)

ts_calendar_heatmap_plot(
  .data          = data_tbl
  , .date_col    = date_col
  , .value_col   = value
  , .interactive = FALSE
)

Time Series Clustering via Features:

data_tbl <- ts_to_tbl(AirPassengers) %>%
  mutate(group_id = rep(1:12, 12))

output <- ts_feature_cluster(
  .data = data_tbl,
  .date_col = date_col,
  .value_col = value,
  group_id,
  .features = c("acf_features","entropy"),
  .scale = TRUE,
  .prefix = "ts_",
  .centers = 3
)

ts_feature_cluster_plot(
  .data = output,
  .date_col = date_col,
  .value_col = value,
  .center = 2,
  group_id
)

Time to/from Event Analysis

library(dplyr)
df <- ts_to_tbl(AirPassengers) %>% select(-index)

ts_time_event_analysis_tbl(
  .data = df,
  .horizon = 6,
  .date_col = date_col,
  .value_col = value,
  .direction = "both"
) %>%
  ts_event_analysis_plot()


ts_time_event_analysis_tbl(
  .data = df,
  .horizon = 6,
  .date_col = date_col,
  .value_col = value,
  .direction = "both"
) %>%
  ts_event_analysis_plot(.plot_type = "individual")

ARIMA Simulators

output <- ts_arima_simulator()
output$plots$static_plot

Automatic Workflows which can be thought of as Boiler Plate Time Series modeling. This is in it’s infancy in this package.

Auto WorkflowsBoilerplate Workflow
ts_auto_arima()Boilerplate Workflow
ts_auto_arima_xgboost()Boilerplate Workflow
ts_auto_croston()Boilerplate Workflow
ts_auto_exp_smoothing()Boilerplate Workflow
ts_auto_glmnet()Boilerplate Workflow
ts_auto_lm()Boilerplate Workflow
ts_auto_mars()Boilerplate Workflow
ts_auto_nnetar()Boilerplate Workflow
ts_auto_prophet_boost()Boilerplate Workflow
ts_auto_prophet_reg()Boilerplate Workflow
ts_auto_smooth_es()Boilerplate Workflow
ts_auto_svm_poly()Boilerplate Workflow
ts_auto_svm_rbf()Boilerplate Workflow
ts_auto_theta()Boilerplate Workflow
ts_auto_xgboost()Boilerplate Workflow

This is just a start of what is in this package!

Copy Link

Version

Install

install.packages('healthyR.ts')

Monthly Downloads

361

Version

0.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Steven Sanderson

Last Published

November 15th, 2023

Functions in healthyR.ts (0.3.0)

step_ts_velocity

Recipes Time Series velocity Generator
step_ts_acceleration

Recipes Time Series Acceleration Generator
ts_auto_lm

Boilerplate Workflow
ts_auto_arima

Boilerplate Workflow
ts_auto_glmnet

Boilerplate Workflow
ts_auto_exp_smoothing

Boilerplate Workflow
ts_arima_simulator

Simulate ARIMA Model
ts_adf_test

Augmented Dickey-Fuller Test for Time Series Stationarity
ts_acceleration_vec

Vector Function Time Series Acceleration
ts_auto_mars

Boilerplate Workflow
ts_auto_nnetar

Boilerplate Workflow
ts_auto_croston

Boilerplate Workflow
ts_auto_prophet_reg

Boilerplate Workflow
ts_auto_smooth_es

Boilerplate Workflow
ts_auto_svm_poly

Boilerplate Workflow
ts_auto_arima_xgboost

Boilerplate Workflow
ts_auto_recipe

Build a Time Series Recipe
ts_auto_svm_rbf

Boilerplate Workflow
ts_auto_theta

Boilerplate Workflow
ts_auto_prophet_boost

Boilerplate Workflow
ts_auto_xgboost

Boilerplate Workflow
ts_feature_cluster

Time Series Feature Clustering
ts_brownian_motion

Brownian Motion
ts_brownian_motion_augment

Brownian Motion
ts_feature_cluster_plot

Time Series Feature Clustering
ts_calendar_heatmap_plot

Time Series Calendar Heatmap
ts_event_analysis_plot

Time Series Event Analysis Plot
ts_extract_auto_fitted_workflow

Extract Boilerplate Items
ts_model_auto_tune

Time Series Model Tuner
ts_compare_data

Compare data over time periods
ts_model_compare

Compare Two Time Series Models
ts_brownian_motion_plot

Auto-Plot a Geometric/Brownian Motion Augment
ts_lag_correlation

Time Series Lag Correlation Analysis
ts_ma_plot

Time Series Moving Average Plot
ts_growth_rate_vec

Vector Function Time Series Growth Rate
ts_growth_rate_augment

Augment Data with Time Series Growth Rates
ts_geometric_brownian_motion_augment

Geometric Brownian Motion
ts_get_date_columns

Get date or datetime variables (column names)
ts_model_spec_tune_template

Time Series Model Spec Template
ts_model_rank_tbl

Model Rank
ts_scale_fill_colorblind

Provide Colorblind Compliant Colors
ts_scale_color_colorblind

Provide Colorblind Compliant Colors
ts_info_tbl

Get Time Series Information
ts_random_walk

Random Walk Function
ts_forecast_simulator

Time-series Forecasting Simulator
ts_sma_plot

Simple Moving Average Plot
ts_qq_plot

Time Series Model QQ Plot
ts_geometric_brownian_motion

Geometric Brownian Motion
ts_wfs_ets_reg

Auto ETS Workflowset Function
ts_random_walk_ggplot_layers

Get Random Walk ggplot2 layers
ts_is_date_class

Check if an object is a date class
ts_qc_run_chart

Quality Control Run Chart
ts_scedacity_scatter_plot

Time Series Model Scedacity Plot
ts_wfs_lin_reg

Auto Linear Regression Workflowset Function
ts_wfs_arima_boost

Auto Arima XGBoost Workflowset Function
ts_splits_plot

Time Series Splits Plot
ts_time_event_analysis_tbl

Event Analysis
ts_wfs_auto_arima

Auto Arima (Forecast auto_arima) Workflowset Function
ts_wfs_svm_rbf

Auto SVM RBF (Kernlab) Workflowset Function
ts_to_tbl

Coerce a time-series object to a tibble
ts_velocity_augment

Augment Function Velocity
util_difflog_ts

Differencing with Log Transformation to Make Time Series Stationary
ts_wfs_mars

Auto MARS (Earth) Workflowset Function
ts_vva_plot

Time Series Value, Velocity and Acceleration Plot
ts_velocity_vec

Vector Function Time Series Acceleration
util_doubledifflog_ts

Double Differencing with Log Transformation to Make Time Series Stationary
util_doublediff_ts

Double Differencing to Make Time Series Stationary
ts_wfs_nnetar_reg

Auto NNETAR Workflowset Function
util_singlediff_ts

Single Differencing to Make Time Series Stationary
util_log_ts

Logarithmic Transformation to Make Time Series Stationary
ts_wfs_xgboost

Auto XGBoost (XGBoost) Workflowset Function
ts_wfs_svm_poly

Auto SVM Poly (Kernlab) Workflowset Function
ts_wfs_prophet_reg

Auto PROPHET Regression Workflowset Function
ci_lo

Confidence Interval Generic
auto_stationarize

Automatically Stationarize Time Series Data
get_recipe_call

Misc for boilerplate
ci_hi

Confidence Interval Generic
calibrate_and_plot

Helper function - Calibrate and Plot
color_blind

Provide Colorblind Compliant Colors
internal_ts_backward_event_tbl

Event Analysis
internal_ts_both_event_tbl

Event Analysis
model_extraction_helper

Model Method Extraction Helper
ts_acceleration_augment

Augment Function Acceleration
tidy_fft

Tidy Style FFT
assign_value

Misc for boilerplate
arima_string

Forecast arima.string
%>%

Pipe operator
chr_assign

Misc for boilerplate
required_pkgs.step_ts_acceleration

Requited Packages
tidyeval

Tidy eval helpers
internal_ts_forward_event_tbl

Event Analysis