Description Usage Arguments See Also Examples
View source: R/DetectAnomalies_FLAM.R
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:
Create a time series object using data
,
frequency
and time
.
Decompose the time series into three components using STL, i.e. seasonal, trend and residual.
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.
According to the change point detected in last step, split the original time series into non-overlapping windows of varying size.
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.
1 2 | DetectAnomalies_FLAM(data, period, time = NULL, max_anoms = 0.03,
direction = "both", ...)
|
data |
A numeric vector containing values observed at times specified in
|
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 |
direction |
Directionality of the anomalies to be deteted. Options are: 'pos', 'neg' and 'both'. Defaults to be 'both' |
stl
flamCV
AnomalyDetectionVec
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.