R/time_recompose.R
time_recompose.Rd
Recompose bands separating anomalies from "normal" observations
time_recompose(data)
A tibble
or tbl_time
object that has been
processed with time_decompose()
and anomalize()
.
Returns a tbl_time
object.
The time_recompose()
function is used to generate bands around the
"normal" levels of observed values. The function uses the remainder_l1
and remainder_l2 levels produced during the anomalize()
step
and the season and trend/median_spans values from the time_decompose()
step to reconstruct bands around the normal values.
The following key names are required: observed:remainder from the
time_decompose()
step and remainder_l1 and remainder_l2 from the
anomalize()
step.
Time Series Anomaly Detection Functions (anomaly detection workflow):
library(dplyr)
data(tidyverse_cran_downloads)
# Basic Usage
tidyverse_cran_downloads %>%
time_decompose(count, method = "stl") %>%
anomalize(remainder, method = "iqr") %>%
time_recompose()
#> # A time tibble: 6,375 × 11
#> # Index: date
#> # Groups: package [15]
#> package date observed season trend remainder remainde…¹ remai…² anomaly
#> <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 broom 2017-01-01 1053 -1007. 1708. 352. -1725. 1704. No
#> 2 broom 2017-01-02 1481 340. 1731. -589. -1725. 1704. No
#> 3 broom 2017-01-03 1851 563. 1753. -465. -1725. 1704. No
#> 4 broom 2017-01-04 1947 526. 1775. -354. -1725. 1704. No
#> 5 broom 2017-01-05 1927 430. 1798. -301. -1725. 1704. No
#> 6 broom 2017-01-06 1948 136. 1820. -8.11 -1725. 1704. No
#> 7 broom 2017-01-07 1542 -988. 1842. 688. -1725. 1704. No
#> 8 broom 2017-01-08 1479 -1007. 1864. 622. -1725. 1704. No
#> 9 broom 2017-01-09 2057 340. 1887. -169. -1725. 1704. No
#> 10 broom 2017-01-10 2278 563. 1909. -194. -1725. 1704. No
#> # … with 6,365 more rows, 2 more variables: recomposed_l1 <dbl>,
#> # recomposed_l2 <dbl>, and abbreviated variable names ¹remainder_l1,
#> # ²remainder_l2