time_decompose {anomalize} | R Documentation |
Decompose a time series in preparation for anomaly detection
Description
Decompose a time series in preparation for anomaly detection
Usage
time_decompose(
data,
target,
method = c("stl", "twitter"),
frequency = "auto",
trend = "auto",
...,
merge = FALSE,
message = TRUE
)
Arguments
data |
A |
target |
A column to apply the function to |
method |
The time series decomposition method. One of |
frequency |
Controls the seasonal adjustment (removal of seasonality).
Input can be either "auto", a time-based definition (e.g. "1 week"),
or a numeric number of observations per frequency (e.g. 10).
Refer to |
trend |
Controls the trend component For stl, the trend controls the sensitivity of the lowess smoother, which is used to remove the remainder. For twitter, the trend controls the period width of the median, which are used to remove the trend and center the remainder. |
... |
Additional parameters passed to the underlying method functions. |
merge |
A boolean. |
message |
A boolean. If |
Details
The time_decompose()
function generates a time series decomposition on
tbl_time
objects. The function is "tidy" in the sense that it works
on data frames. It is designed to work with time-based data, and as such
must have a column that contains date or datetime information. The function
also works with grouped data. The function implements several methods
of time series decomposition, each with benefits.
STL:
The STL method (method = "stl"
) implements time series decomposition using
the underlying decompose_stl()
function. If you are familiar with stats::stl()
,
the function is a "tidy" version that is designed to work with tbl_time
objects.
The decomposition separates the "season" and "trend" components from
the "observed" values leaving the "remainder" for anomaly detection.
The user can control two parameters: frequency
and trend
.
The frequency
parameter adjusts the "season" component that is removed
from the "observed" values. The trend
parameter adjusts the
trend window (t.window
parameter from stl()
) that is used.
The user may supply both frequency
and trend
as time-based durations (e.g. "90 days") or numeric values
(e.g. 180) or "auto", which predetermines the frequency and/or trend
based on the scale of the time series.
Twitter:
The Twitter method (method = "twitter"
) implements time series decomposition using
the methodology from the Twitter AnomalyDetection package.
The decomposition separates the "seasonal" component and then removes
the median data, which is a different approach than the STL method for removing
the trend. This approach works very well for low-growth + high seasonality data.
STL may be a better approach when trend is a large factor.
The user can control two parameters: frequency
and trend
.
The frequency
parameter adjusts the "season" component that is removed
from the "observed" values. The trend
parameter adjusts the
period width of the median spans that are used. The user may supply both frequency
and trend
as time-based durations (e.g. "90 days") or numeric values
(e.g. 180) or "auto", which predetermines the frequency and/or median spans
based on the scale of the time series.
Value
Returns a tbl_time
object.
References
CLEVELAND, R. B., CLEVELAND, W. S., MCRAE, J. E., AND TERPENNING, I. STL: A Seasonal-Trend Decomposition Procedure Based on Loess. Journal of Official Statistics, Vol. 6, No. 1 (1990), pp. 3-73.
See Also
Decomposition Methods (Powers time_decompose
)
Time Series Anomaly Detection Functions (anomaly detection workflow):
Examples
library(dplyr)
data(tidyverse_cran_downloads)
# Basic Usage
tidyverse_cran_downloads %>%
time_decompose(count, method = "stl")
# twitter
tidyverse_cran_downloads %>%
time_decompose(count,
method = "twitter",
frequency = "1 week",
trend = "2 months",
merge = TRUE,
message = FALSE)