The goal of tscompare is to provide an analytics library for comparing multiple timeseries.
You can install lhe development version of tscompare from GitHub with:
# install.packages("devtools")
devtools::install_github("roboton/tscompare")
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)
#> Warning in ts_analysis(test_data, "test_analysis", start_date = start_date, :
#> computing ts models for group_id: test_analysis
#> test_analysis/group_timeseries_model.rds
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.
#> Saving 7 x 5 in image
#> Saving 7 x 5 in image
paste("timeseries analysis output in directory:", output_dir)
#> [1] "timeseries analysis output in directory: test_analysis"
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")
}