knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

tscompare

The goal of tscompare is to provide an analytics library for comparing multiple timeseries.

Installation

You can install lhe development version of tscompare from GitHub with:

# install.packages("devtools")
devtools::install_github("roboton/tscompare")

Example

This is a basic example with simulated data with two timeseries anomalies (one over and one under).

library(tscompare)
set.seed(143)
num_dates <- 90
num_timeseries <- 30
# generate synthetic data
test_data <- setNames(
  merge(as.character(1:num_timeseries),
        seq(Sys.Date(), Sys.Date() + (num_dates - 1), by = 1),
        colnames = c("ts_id", "date")), c("ts_id", "date"))
start_date <- Sys.Date() + floor(num_dates / 2)
test_data$count <- sapply(1:(num_dates*num_timeseries),
                          function(x) { rpois(1, 50) })
# ts anomalies
test_data[test_data$ts_id == "1" &
            test_data$date > start_date, "count"] <- 100
test_data[test_data$ts_id == "2" &
            test_data$date > start_date, "count"] <- 1

output_dir <- ts_analysis(
  test_data, "test_analysis", start_date = start_date, period = "day",
  sig_p = 0.01)
paste("timeseries analysis output in directory:", output_dir)
output_pngs <- list.files("test_analysis/output", pattern = ".png$")

for(png in output_pngs){
  cat("\n") 
  cat("![", png, "](test_analysis/output/", png, ")", sep = "")
  cat("\n")
}


roboton/chwork documentation built on June 21, 2022, 6:18 a.m.