我使用Anomalize包来检测异常,但即使我将Date定义为索引,也会得到所述的错误:
样本代码:
x <- as.data.frame(data %>%
group_by(date,acc_id) %>%
summarise(count = as.numeric(n_distinct(d_id))) %>%
ungroup())
x$acc_id <- as.character(x$acc_id)
x <- x %>%
tibbletime::as_tbl_time(index = date)
x %>%
time_decompose(count, method = "twitter", trend = "2 months") %>%
anomalize(remainder, method = "gesd") %>%
time_recompose() %>%
plot_anomalies(time_recomposed = TRUE)错误:
Mutate_impl中的错误(.data,dots):评估错误:类日期的索引只允许年、季度、月、周和日周期。
dput(head(x))
structure(list(date = structure(c(17532, 17532, 17532, 17532, 17532, 17532), class = "Date"), acc_id = c("a44444", "gg555", "0195459b-5809-4b54-89b5-1a4376c9f126", "ggg6546", "hhjh77", "hhjh68777"), count = c(3, 1, 1, 1, 1, 1)), .Names = c("date", "acc_id", "count"), row.names = c(NA,
-6L), class = c("tbl_time", "tbl_df", "tbl", "data.frame"), index_quo = ~date, index_time_zone = "UTC")我的目标是按日期和其他一些因素分组,而不是只考虑日期。
发布于 2018-06-10 17:33:41
我也有过同样的问题。帮助我正确定义您的日期格式:
library(tibbletime)
x <- as_tbl_time(x, index = date)
x %>%
as_period("daily")发布于 2018-05-09 08:49:52
从帮助中:
频率控制季节调整(去除季节性)。输入既可以是“自动”,也可以是基于时间的定义(例如"2周“),也可以是每频率观察的数字数(例如10)。请参阅time_frequency()。 趋势控制stl的趋势分量,趋势控制低平滑器的灵敏度,后者用于删除剩余部分。对于twitter,趋势控制中间值的周期宽度,用于删除趋势并将剩余的趋势中心化。
我想你交换了:
x %>%
time_decompose(count, method = "twitter", frequency* = "2 months") %>%
anomalize(remainder, method = "gesd") %>%
time_recompose() %>%
plot_anomalies(time_recomposed = TRUE)但是很难判断是否还有其他问题,因为数据还不够
发布于 2020-08-10 13:38:09
在这条管道上缺少了一个"group_by“。这个错误也出现在失范包的例子中。添加错误后,错误就消失了。这样做是有效的:
x %>%
group_by(acc_id) %>%
time_decompose(count, method = "twitter", trend = "2 months") %>%
anomalize(remainder, method = "gesd") %>%
time_recompose() %>%
plot_anomalies(time_recomposed = TRUE)https://stackoverflow.com/questions/50248133
复制相似问题