Hi All,
I have been trying to do anomaly detection using the anomalize package.
The problem I face is with grouping variables. If there is only column with one distinct value I could be able to run the anomaly detection but if there is multiple time series involved with more than one grouping variable it ends up failing.
Here I have two grouping variables- Product and Location and I tried grouping the data by Product and Location and converted to a tibble object but when i pass the glimpse function it is still not identifying the groups.
I have attached a sample code, if anyone could please help me with this that would be really helpful.
setwd("~/Outlier/R")
Test.df2<-structure(list(Product = c("A1", "A1", "A1", "A1", "B1", "B1", "B1", "B1"), Location = c("A", "A", "A", "A", "A", "B", "A", "C"), Period = c("Sep 2017", "Oct 2017", "Nov 2017", "Dec 2017", "Sep 2017", "Oct 2017", "Nov 2017", "Dec 2017"), Units = c(5.399993, 9, 10, 9, 5, 1, 3, 1)), row.names = c(NA, 8L), class = "data.frame")
Test.df2$Period<-lubridate::my(Test.df2$Period)
Test.df2[is.na(Test.df2)]<-0
Test.df2<-Test.df2 %>% group_by(Product,Location)
Test.df2<-as_tibble(Test.df2)
glimpse(Test.df2)
Test.df2.anomaly<- Test.df2 %>% time_decompose(Units,merge = T,method = 'stl',frequency = "auto", trend = "auto")%>% anomalize(remainder,method = 'gesd',alpha = 0.05,max_anoms = 0.2) %>% time_recompose()