I'm trying to use R Anomalize package to check the anomalies in our revenue,
I'm following the instructions from Quick start documentation below, https://cran.r-project.org/web/packages/anomalize/vignettes/anomalize_quick_start_guide.html
In my case, I am trying to convert the data frame into a tibble time object as below,
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))
This is how the tibble time object looks,
> 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
But, when trying to do anomaly detection with below code,
revenue_anomalized <- revenue %>%
time_decompose(count, merge = TRUE) %>%
anomalize(remainder) %>%
time_recompose()
I'm getting the following error,
Error: Problem with
mutate()
inputnested.col
.
x Problem withmutate()
inputdate
.
x Only year, quarter, month, week, and day periods are allowed for an index of class Date
ℹ Inputdate
iscollapse_index(...)
.
ℹ Inputnested.col
ispurrr::map(.x = data, .f = .f, target = count, ...)
.
Runrlang::last_error()
to see where the error occurred.
In addition: Warning messages:
1: Problem withmutate()
inputnested.col
.
ℹ can not calculate periodicity of 1 observation
ℹ Inputnested.col
ispurrr::map(.x = data, .f = .f, target = count, ...)
.
2: In xts::periodicity(idx) :
can not calculate periodicity of 1 observation
Any help would be greatly appreciated. Thanks in advance.