Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native STL can detect anomaly but time_decompose not #36

Open
edvardoss opened this issue Jul 9, 2019 · 1 comment
Open

native STL can detect anomaly but time_decompose not #36

edvardoss opened this issue Jul 9, 2019 · 1 comment

Comments

@edvardoss
Copy link

edvardoss commented Jul 9, 2019

dfr <- tibble(ds = as.Date(c('2017-03-01', '2017-04-01', '2017-05-01', '2017-06-01', '2017-07-01', '2017-08-01', '2017-09-01',
                                  '2017-10-01', '2017-11-01', '2017-12-01', '2018-01-01', '2018-02-01', '2018-03-01', '2018-04-01', '2018-05-01', '2018-06-01',
                                  '2018-07-01', '2018-08-01', '2018-09-01', '2018-10-01', '2018-11-01', '2018-12-01', '2019-01-01', '2019-02-01', '2019-03-01',
                                  '2019-04-01', '2019-05-01', '2019-06-01')),
  
                  y=c(12.95, 1.12, 4.48, 17.85, 0.14, 0.7, 1.75, 3.43, 5.18, 14.91, 4.27, 1.82, 4.83, 2.94, 3.22, 6.72, 3.36, 2.52,
                      5.88, 23.1, 13.44, 1244.22, 1.26, 9.66, 22.05, 2.94, 6.3, 1.26))
# outlier in 2018-12-01
decmp <- time_decompose(data = dfr,target = y,method = "stl", frequency = "12 months",trend = "auto",message = FALSE)
fit <- decmp %>% anomalize(remainder,method = "gesd",max_anoms = .3,verbose = FALSE)
# 1244 in 2018-12-01 is seasonality!!!!! and remainder = -0.2793775
fit %>% time_recompose() %>% plot_anomalies()
fit %>% time_recompose() %>% plot_anomaly_decomposition()

#try native STL

t <- ts(data = dfr$y,start = c(2017,3),frequency = 12)
library(highcharter)
hchart(stl(t,s.window = "periodic"))
# in 2018-12-01  remainder is 558 and in this case is anomaly!!!!

# try twitter with same results
decmp <- time_decompose(data = dfr,target = y,method = "twitter", frequency = "12 months",trend = "auto",message = FALSE)
fit <- decmp %>% anomalize(remainder,method = "gesd",max_anoms = .3,verbose = FALSE)
fit

# try original twitter
# devtools::install_github("twitter/AnomalyDetection")
library(AnomalyDetection)
AnomalyDetectionTs(x = dfr)
# timestamp               anoms
# 1 2018-10-01 03:00:00   23.10
# 2 2018-12-01 03:00:00 1244.22

@ranalytics
Copy link

Log-transform the values of y, it'll work just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants