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-23 16:46:08 measurement 14.7   10.69926    6.205650    15.24626
## 2  2017-06-23 16:47:08 measurement 32.4   24.69661   20.580226    29.24058
## 3  2017-06-23 16:48:08 measurement 30.4   26.45181   21.449774    31.39530
## 4  2017-06-23 16:49:08 measurement 33.9   25.64934   21.116739    29.96850
## 5  2017-06-23 16:50:08 measurement 21.5   23.04859   18.883298    27.43685
## 6  2017-06-23 16:51:08 measurement 15.5   17.68592   13.649430    21.76127
## 7  2017-06-23 16:52:08 measurement 15.2   17.98227   13.872468    21.88298
## 8  2017-06-23 16:53:08 measurement 13.3   14.14678    8.750246    19.20916
## 9  2017-06-23 16:54:08 measurement 19.2   15.99739   11.581395    19.91503
## 10 2017-06-23 16:55:08 measurement 27.3   25.30637   20.658131    29.65120
## 11 2017-06-23 16:56:08 measurement 26.0   23.91831   19.111380    28.43118
## 12 2017-06-23 16:57:08 measurement 30.4   24.87587   18.572514    30.65163
## 13 2017-06-23 16:58:08 measurement 15.8   15.31191    8.264808    21.96496
## 14 2017-06-23 16:59:08 measurement 19.7   19.46759   14.419048    24.67862
## 15 2017-06-23 17:00:08 measurement 15.0   12.31668    2.821255    20.46763
## 16 2017-06-23 17:01:08 measurement 21.4   21.91689   17.694221    26.42829
##    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