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)
Related Topics
Writing R Function with If Enviornment
Creating a Sequential List of Letters with R
Force No Default Selection in Selectinput()
Defining Minimum Point Size in Ggplot2 - Geom_Point
Meaning of Band Width in Ggplot Geom_Smooth Lm
Writing Functions in R, Keeping Scoping in Mind
How to Knitr Markdown Straight Out of Your Workspace Using Rstudio
Unnesting a List of Lists in a Data Frame Column
Stl Decomposition of Time Series with Missing Values for Anomaly Detection
Extract Text from Two-Column PDF with R
How to Display a Busy Indicator in a Shiny App
Geom_Bar() + Pictograms, How To
How to Plot a Classification Graph of a Svm in R
Importing Common Yaml in Rstudio/Knitr Document
An Elegant Way to Change Columns Type in Dataframe in R
Running Multiple Linear Regressions Across Several Columns of a Data Frame in R