# Harbinger Package
# version 1.0.777
source("https://raw.githubusercontent.com/cefet-rj-dal/harbinger/master/jupyter.R")
#loading Harbinger
load_library("daltoolbox")
load_library("harbinger")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform Loading required package: harbinger
#Creating dataset
n <- 100 # size of each segment
serie1 <- c(sin((1:n)/pi), 2*sin((1:n)/pi), 10 + sin((1:n)/pi),
10-10/n*(1:n)+sin((1:n)/pi)/2, sin((1:n)/pi)/2)
serie2 <- 2*c(sin((1:n)/pi), 2*sin((1:n)/pi), 10 + sin((1:n)/pi),
10-10/n*(1:n)+sin((1:n)/pi)/2, sin((1:n)/pi)/2)
event <- rep(FALSE, length(serie1))
event[c(100, 200, 300, 400)] <- TRUE
dataset <- data.frame(serie1, serie2, event)
#ploting the time series
plot_ts(x = 1:length(dataset$serie1), y = dataset$serie1)
#ploting serie #2
plot_ts(x = 1:length(dataset$serie2), y = dataset$serie2)
# establishing drift method
model <- hcd_eddm()
# fitting the model
model <- fit(model, dataset)
# making detections
detection <- detect(model, dataset)
Error in if (x == 1) {: the condition has length > 1 Traceback: 1. detect(model, dataset) 2. detect.hcd_eddm(model, dataset) 3. update(obj, data[1])
# filtering detected events
print(detection[(detection$event),])
# evaluating the detections
evaluation <- evaluate(model, detection$event, dataset$event)
print(evaluation$confMatrix)
# ploting the results
grf <- har_plot(model, dataset$serie1, detection, dataset$event)
plot(grf)