Clean anomalies from anomalized data

clean_anomalies(data)

Arguments

data

A tibble or tbl_time object.

Value

Returns a tibble / tbl_time object with a new column "observed_cleaned".

Details

The clean_anomalies() function is used to replace outliers with the seasonal and trend component. This is often desirable when forecasting with noisy time series data to improve trend detection.

To clean anomalies, the input data must be detrended with time_decompose() and anomalized with anomalize(). The data can also be recomposed with time_recompose().

See also

Time Series Anomaly Detection Functions (anomaly detection workflow):

Examples

library(dplyr) # Needed to pass CRAN check / This is loaded by default set_time_scale_template(time_scale_template()) data(tidyverse_cran_downloads) tidyverse_cran_downloads %>% time_decompose(count, method = "stl") %>% anomalize(remainder, method = "iqr") %>% clean_anomalies()
#> # A time tibble: 6,375 x 10 #> # Index: date #> # Groups: package [15] #> package date observed season trend remainder remainder_l1 remainder_l2 #> <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 broom 2017-01-01 1053. -1007. 1708. 352. -1725. 1704. #> 2 broom 2017-01-02 1481 340. 1731. -589. -1725. 1704. #> 3 broom 2017-01-03 1851 563. 1753. -465. -1725. 1704. #> 4 broom 2017-01-04 1947 526. 1775. -354. -1725. 1704. #> 5 broom 2017-01-05 1927 430. 1798. -301. -1725. 1704. #> 6 broom 2017-01-06 1948 136. 1820. -8.11 -1725. 1704. #> 7 broom 2017-01-07 1542 -988. 1842. 688. -1725. 1704. #> 8 broom 2017-01-08 1479. -1007. 1864. 622. -1725. 1704. #> 9 broom 2017-01-09 2057 340. 1887. -169. -1725. 1704. #> 10 broom 2017-01-10 2278 563. 1909. -194. -1725. 1704. #> # … with 6,365 more rows, and 2 more variables: anomaly <chr>, #> # observed_cleaned <dbl>