DetectAnomalies_FLAM: Anomalies and Change Points Detection using FLAM

Description Usage Arguments See Also Examples

View source: R/DetectAnomalies_FLAM.R

Description

A technique for detecting both past and current anomalies in an univariate time series given all observations up to and including the current time.

The algorithm used in this function is as follows:

  1. Create a time series object using data, frequency and time.

  2. Decompose the time series into three components using STL, i.e. seasonal, trend and residual.

  3. Fit the trend component using Fused Lasso Additive Model (FLAM), where it is estimated to piecewise constant with a small number of adaptively-chosen knots.

  4. According to the change point detected in last step, split the original time series into non-overlapping windows of varying size.

  5. If the window size is large than 2 periods, detect anomalies within the window by applying the AnomalyDetectionVec function provided by twitter. Otherwise, mark all the observations that deviate from the median by more than 2.58 Median Absolute Deviation (MAD) as anomalies.

Usage

1
2
DetectAnomalies_FLAM(data, period, time = NULL, max_anoms = 0.03,
  direction = "both", ...)

Arguments

data

A numeric vector containing values observed at times specified in time.

period

A numeric value indicating the number of observations in a single period, and used during seasonal decomposition.

time

A corresponding vector specifying times/dates. If this parameter is missing, it will be set as starting from "1990-01-01".

max_anoms

Maximum number of anomalies will be detected as a percentage of the data

direction

Directionality of the anomalies to be deteted. Options are: 'pos', 'neg' and 'both'. Defaults to be 'both'

See Also

stl flamCV AnomalyDetectionVec

Examples

1
2
3
4
5
6
data <- SessionSuccessRate
p1 <- PlotTimeSeries(data, "Day", c("Value"))
anomalies <- DetectAnomalies_FLAM(data$Value, 7, time = data$Day)
p1 <- AddShadedRegion(p1, c(1:dim(data)[1]) %in% anomalies$change.points, color = "red")
p1 <- AddShadedRegion(p1, c(1:dim(data)[1]) %in% anomalies$anomaly.points, color = "blue")
p1

jingjin1018/anetimeseries documentation built on May 19, 2019, 10:35 a.m.