我正在尝试使用 R Anomalize 包来检查我们收入的异常情况,
我正在按照下面的快速入门文档中的说明进行操作, https://cran.r-project.org/web/packages/anomalize/vignettes/anomalize_quick_start_guide.html
就我而言,我正在尝试将数据框转换为 tibble 时间对象,如下所示,
library(anomalize)
library(tibble)
library(tibbletime)
library(tidyverse)
revenue <- read.csv(file = '../data/revenue.csv') %>%
mutate(date = as.Date(date)) %>%
as_tbl_time(index = date) %>%
group_by(country_code, date) %>%
summarise(count = sum(`total_revenue`, na.rm = TRUE))
这就是 tibble 时间对象的外观,
> revenue
# A time tibble: 807 x 3
# Index: date
# Groups: country_code [39]
country_code date count
<chr> <date> <dbl>
1 AE 2020-09-01 4688.
2 AE 2020-09-02 3054.
3 AE 2020-09-03 3987.
4 AE 2020-09-04 3337.
5 AE 2020-09-05 2947.
6 AE 2020-09-06 3597.
7 AE 2020-09-07 3737.
8 AE 2020-09-08 4187.
9 AE 2020-09-09 3038.
10 AE 2020-09-10 3803.
# … with 797 more rows
但是,当尝试使用以下代码进行异常检测时,
revenue_anomalized <- revenue %>%
time_decompose(count, merge = TRUE) %>%
anomalize(remainder) %>%
time_recompose()
我收到以下错误,
错误:
mutate()
输入有问题nested.col
。
xmutate()
输入问题date
。
x 对于 Date ℹ 类的索引,仅允许年、季度、月、周和日期
间 ℹ 输入date
为collapse_index(...)
。
ℹ 输入nested.col
是purrr::map(.x = data, .f = .f, target = count, ...)
。
运行rlang::last_error()
以查看错误发生的位置。
另外:警告消息:
1:mutate()
输入问题nested.col
。
ℹ 不能计算 1 次观察的周期性
ℹ 输入nested.col
是purrr::map(.x = data, .f = .f, target = count, ...)
.
2:在 xts::periodicity(idx) 中:
无法计算 1 次观察的周期性
任何帮助将不胜感激。提前致谢。