小错误:除非发生严重错误,否则不应发生

时间:2019-05-24 11:06:57

标签: r time-series tidyverse anomaly-detection

问题标题不是夸张的,它是实际的错误消息:

Error: Attribute, `index_quo`, has been lost, but class is still `tbl_time`. This should not happen unless something has gone horribly wrong.
19.
stop(glue::glue(..., .sep, .envir = parent.frame()), call. = FALSE)
18.
glue_stop("Attribute, `index_quo`, has been lost, ", "but class is still `tbl_time`. This should not happen unless ", "something has gone horribly wrong.")
17.
get_index_quo(.tbl_time)
16.
is_quosure(quo)
15.
quo_squash(quo)
14.
type_of(.x)
13.
switch_type(expr, `NULL` = "NULL", symbol = as_string(expr), quosure = , language = if (is_data_pronoun(expr)) { data_pronoun_name(expr) %||% "<unknown>" } else { ...
12.
expr_name(quo_squash(quo))
11.
rlang::quo_name(get_index_quo(.tbl_time))
10.
get_index_char(x)
9.
get_index_char(x) %in% colnames(x_tbl)
8.
`[.tbl_time`(x, seq_len(n), , drop = FALSE)
7.
x[seq_len(n), , drop = FALSE]
6.
head.data.frame(x, n)
5.
head(x, n)

导致它的特定部分是这样的:

ad_window <- function(...) {
  data <- tibble(...)
  fit <-
    anomalize::decompose_twitter(data = data,
                                 target = count,
                                 message = FALSE) %>%
    anomalize(remainder, method = "iqr") %>%
    time_recompose()
  return(fit)
}

tidyverse_cran_downloads %>%
  nest(-group_cols())  %>%
  filter(package %in% c("tidyr")) %>%  # just to make it quick
  mutate(
    diag = map(
      data, ~ ptile_dfr(
        ., ad_window, .size = 43
        )
      )
    ) -> tile3result

tile3result$diag

似乎与in this question遇到问题的.size参数有关,该参数由@ earo-wang解决了

如果我将.size自变量缩小一个记录,则会发生:

tidyverse_cran_downloads %>%
  nest(-group_cols())  %>%
  filter(package %in% c("tidyr")) %>%  # just to make it quick
  mutate(
    diag = map(
      data, ~ ptile_dfr(
        ., ad_window, .size = 42
        )
      )
    ) -> tile2result

tile2result$diag

Error in stats::stl(., s.window = "periodic", robust = TRUE) : series is not periodic or has less than two periods

与我先前的问题有相同的错误,除了我使用的是ptile,而不是pslide,并且使用的是比原始查询更高的 .size问题。

数据的n为425,仍远高于.size值:

tidyverse_cran_downloads %>% 
  filter(package %in% c("tidyr")) %>% 
  summarise(n())

上一个问题的答案一直存在

tidyverse_cran_downloads %>%
  nest(-group_cols())  %>%
  filter(package %in% c("tidyr")) %>%  # just to make it quick
  mutate(
    anoms = map(
      data, ~ pslide_dfr(
        ., ad_window, .size = 7 * 3
        )
      )
    ) -> slideresult

slideresult$anoms

简单地将其转换为ptile错误:

tidyverse_cran_downloads %>%
  nest(-group_cols())  %>%
  filter(package %in% c("tidyr")) %>%  # just to make it quick
  mutate(
    diag = map(
      data, ~ ptile_dfr(
        ., ad_window, .size = 7 * 3
        )
      )
    ) -> tileresult

tileresult$diag

Error in stats::stl(., s.window = "periodic", robust = TRUE) : series is not periodic or has less than two periods

这让我感到困惑,因为: 1)ptile是否应该取代pslide? 2)两种情况下数据的频率是否不应该相同?

0 个答案:

没有答案