Installation

Either you try stable CRAN version

install.packages("cbar")

Or unstable development version

devtools::install_github("zedoul/cbar")

You’ll need to use library to load as follows:

library(cbar)

Introduction

cbar is an R package for detecting anomaly in time-series data with Bayesian inference. Although there are many packages to detect anomaly in the world, relatively few packages provide functions for visually and/or analytically abstracting the output.

The cbar package aims to provide simple-to-use functions for detecting anomaly, and abstracting the analysis output.

Detecting anomaly

A minimal example would be like:

library(cbar)

.data <- mtcars
rownames(.data) <- NULL
datetime <- seq(from = Sys.time(), length.out = nrow(.data), by = "mins")
.data <- cbind(datetime = datetime, .data)

ref_session <- 1:16
mea_session <- 17:nrow(.data)

.cbar <- cbar(.data, ref_session, mea_session)
plot_ts(.cbar)

You may wonder why it uses reference and measurement instead of training and testing. In anomaly detection, espeically in telecommuncation field, performance reference period refers a period which serves a basis for defining anomaly, and performance measurement period refers the period during which performance parameters are measured.

If you hope to see the abstracted outcome, then:

summarise_session(.cbar)
##       session n_anomaly n_total  rate
## 1   reference         0      16 0.000
## 2 measurement         2      16 0.125

or you can just use print function as follows:

print(.cbar)
##       session n_anomaly n_total  rate
## 1   reference         0      16 0.000
## 2 measurement         2      16 0.125

If you hope to see details of those anomalies:

summarise_anomaly(.cbar, .session = "measurement")
##               datetime     session    y point_pred lower_bound upper_bound
## 1  2017-06-27 12:49:12 measurement 14.7   10.87025    6.064796    16.19646
## 2  2017-06-27 12:50:12 measurement 32.4   24.77453   20.374624    29.27430
## 3  2017-06-27 12:51:12 measurement 30.4   26.62004   21.596691    32.22140
## 4  2017-06-27 12:52:12 measurement 33.9   25.73697   20.955055    30.74651
## 5  2017-06-27 12:53:12 measurement 21.5   23.18440   18.920613    27.86051
## 6  2017-06-27 12:54:12 measurement 15.5   17.53416   13.254213    21.41196
## 7  2017-06-27 12:55:12 measurement 15.2   17.93968   13.787040    22.19688
## 8  2017-06-27 12:56:12 measurement 13.3   14.37706    8.948065    20.22298
## 9  2017-06-27 12:57:12 measurement 19.2   15.98489   11.272477    19.89496
## 10 2017-06-27 12:58:12 measurement 27.3   25.35061   20.936606    29.66173
## 11 2017-06-27 12:59:12 measurement 26.0   23.94081   18.895895    29.15398
## 12 2017-06-27 13:00:12 measurement 30.4   24.73569   18.112768    30.58411
## 13 2017-06-27 13:01:12 measurement 15.8   15.47864    7.841035    23.23718
## 14 2017-06-27 13:02:12 measurement 19.7   19.23585   12.604314    24.46015
## 15 2017-06-27 13:03:12 measurement 15.0   12.28600    2.414053    20.42559
## 16 2017-06-27 13:04:12 measurement 21.4   22.06509   18.031695    26.49529
##    anomaly
## 1    FALSE
## 2     TRUE
## 3    FALSE
## 4     TRUE
## 5    FALSE
## 6    FALSE
## 7    FALSE
## 8    FALSE
## 9    FALSE
## 10   FALSE
## 11   FALSE
## 12   FALSE
## 13   FALSE
## 14   FALSE
## 15   FALSE
## 16   FALSE