Stl Decomposition of Time Series with Missing Values for Anomaly Detection

Apply timeseries decomposition (and anomaly detection) over a sliding/tiled window

Approach 2 should work as expected? The error message is related to the stl() that requires at least two seasonal periods to estimate. For example, daily data needs at least 14 observations for stl() to run. Increasing the window size .size = 7 * 3 works fine.

my_decomp <- function(...) {
data <- tibble(...)
anomalize::decompose_twitter(data, count)
}

library(dplyr)
library(anomalize)
tidyverse_cran_downloads %>%
group_by(package) %>%
tidyr::nest() %>%
mutate(diag = purrr::map(data, ~ tsibble::pslide_dfr(., my_decomp, .size = 7 * 3)))
#> # A tibble: 15 x 3
#> package data diag
#> <chr> <list> <list>
#> 1 tidyr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 2 lubridate <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 3 dplyr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 4 broom <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 5 tidyquant <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 6 tidytext <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 7 ggplot2 <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 8 purrr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 9 glue <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 10 stringr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 11 forcats <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 12 knitr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 13 readr <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 14 tibble <tibble [425 × 2]> <tibble [8,506 × 5]>
#> 15 tidyverse <tibble [425 × 2]> <tibble [8,506 × 5]>

continue seasonality of time series from forecast stl decomposition

You could extract the unique values of the seasonal component and then use rep_len to create a vector of length 150 as follows

rep_len(unique(sstl$time.series[, "seasonal"]), length.out = 150)

Sample Image



Related Topics



Leave a reply



Submit