Closed jmablans closed 4 years ago
The forecast package is designed to work with ts
objects, not zoo
.
The behaviour is the same for ts
objects.
> ts <- as.ts(ts)
> outliers <- forecast::tsoutliers(ts)
> dput(outliers)
list(index = c(41L, 73L, 75L, 274L, 292L, 294L, 295L, 296L, 297L,
298L, 300L, 301L, 302L, 303L, 304L, 305L, 306L, 307L, 307L, 309L,
310L, 311L, 312L, 313L, 314L, 315L, 316L, 317L, 318L, 318L, 319L,
319L, 320L, 320L, 321L, 321L, 322L, 322L, 323L, 324L, 324L, 325L,
325L, 326L, 326L, 327L, 327L, 328L, 328L, 329L, 330L, 331L, 331L,
332L, 332L, 333L, 334L, 334L, 335L, 335L, 336L, 336L, 337L, 337L,
338L, 338L, 339L, 339L, 340L, 342L, 343L, 343L, 344L, 344L, 345L,
345L, 346L, 346L, 347L, 347L, 348L, 348L, 349L, 349L, 350L, 350L,
351L, 352L, 353L, 353L, 354L, 354L, 355L, 355L, 356L, 356L, 357L,
357L, 358L, 358L, 359L, 359L, 360L, 360L, 361L, 361L, 362L, 362L,
363L, 363L, 364L, 364L, 365L, 365L, 366L, 366L, 367L, 367L, 368L,
368L, 369L, 369L, 370L, 370L, 371L, 372L, 372L, 373L, 374L, 374L,
375L, 375L, 376L, 376L, 377L, 377L, 378L, 378L, 379L, 379L, 380L,
380L, 381L, 381L, 382L, 382L, 383L, 383L, 384L, 384L, 385L, 385L,
386L, 386L, 387L, 387L, 388L, 388L, 389L, 389L, 390L, 391L, 392L,
393L, 394L, 395L, 395L, 396L, 396L, 397L, 397L, 398L, 398L, 399L,
399L, 400L, 400L, 401L, 401L, 402L, 402L, 403L, 404L, 405L, 406L,
407L, 408L, 409L, 410L, 411L, 412L, 413L, 414L, 415L, 416L, 417L,
418L, 419L, 420L, 421L, 422L, 423L, 424L, 425L, 426L, 427L, 431L,
451L, 472L, 474L, 519L, 530L, 548L, 551L, 552L, 554L, 559L, 568L,
575L, 582L, 600L, 621L, 625L, 637L, 638L, 639L, 640L, 641L, 642L,
643L, 644L, 645L, 646L, 647L, 648L, 649L, 650L, 651L, 652L, 652L,
653L, 654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L,
663L, 664L, 664L, 666L, 667L, 667L, 668L, 668L, 669L, 669L, 670L,
670L, 671L, 671L, 672L, 673L, 673L, 674L, 674L, 675L, 675L, 676L,
676L, 677L, 677L, 678L, 678L, 679L, 679L, 680L, 680L, 681L, 682L,
683L, 684L, 685L, 686L, 687L, 687L, 688L, 688L, 689L, 689L, 690L,
690L, 691L, 691L, 692L, 692L, 693L, 694L, 694L, 695L, 695L, 696L,
696L, 697L, 697L, 698L, 698L, 699L, 699L, 700L, 700L, 701L, 701L,
702L, 702L, 703L, 703L, 704L, 704L, 705L, 705L, 706L, 706L, 707L,
707L, 708L, 708L, 709L, 709L, 710L, 710L, 711L, 711L, 712L, 712L,
713L, 713L, 714L, 714L, 715L, 715L, 716L, 716L, 717L, 717L, 718L,
718L, 719L, 719L, 720L, 720L, 721L, 721L, 722L, 722L, 723L, 723L,
724L, 724L, 725L, 726L, 726L, 727L, 727L, 728L, 728L, 729L, 729L,
730L, 730L, 731L, 731L, 732L, 732L, 733L, 733L, 734L, 734L, 735L,
735L, 736L, 736L, 737L, 737L, 738L, 738L, 739L, 739L, 740L, 740L,
741L, 741L, 742L, 742L, 743L, 743L, 744L, 744L, 745L, 745L, 746L,
746L, 747L, 747L, 748L, 749L, 750L, 751L, 752L, 753L, 754L, 755L,
756L, 756L, 757L, 757L, 758L, 758L, 759L, 759L, 760L, 760L, 761L,
761L, 762L, 762L, 763L, 763L, 764L, 764L, 765L, 765L, 766L, 766L,
767L, 767L, 768L, 768L, 769L, 770L, 770L, 771L, 772L, 773L, 774L,
775L, 776L, 777L, 778L, 779L, 780L, 781L, 782L, 783L, 784L, 785L,
786L, 787L, 788L, 789L, 790L, 791L, 792L, 793L, 794L, 799L, 924L,
979L, 981L, 999L, 1000L, 1007L, 1008L, 1008L, 1009L, 1011L, 1015L,
1027L, 1029L, 1029L, 1030L, 1035L, 1038L, 1044L, 1048L, 1049L,
1049L, 1050L, 1050L, 1051L, 1052L, 1055L), replacements = c(0,
0, 0, 0, 5.5, 12.8333333333333, 14.6666666666667, 16.5, 18.3333333333333,
20.1666666666667, 22.3333333333333, 22.6666666666667, 23, 23.3333333333333,
23.6666666666667, 24, 24.3333333333333, 24.6666666666667, 24.6666666666667,
26.6666666666667, 28.3333333333333, 30, 31.6666666666667, 33.3333333333333,
35, 36.6666666666667, 38.3333333333333, 40, 41.6666666666667,
41.6666666666667, 43.3333333333333, 43.3333333333333, 45, 45,
46.6666666666667, 46.6666666666667, 48.3333333333333, 48.3333333333333,
50, 51.6666666666667, 51.6666666666667, 53.3333333333333, 53.3333333333333,
55, 55, 56.6666666666667, 56.6666666666667, 58.3333333333333,
58.3333333333333, 60, 61.6666666666667, 63.3333333333333, 63.3333333333333,
65, 65, 66.6666666666667, 68.3333333333333, 68.3333333333333,
70, 70, 71.6666666666667, 71.6666666666667, 73.3333333333333,
73.3333333333333, 75, 75, 76.6666666666667, 76.6666666666667,
78.3333333333333, 79.0804597701149, 78.1609195402299, 78.1609195402299,
77.2413793103448, 77.2413793103448, 76.3218390804598, 76.3218390804598,
75.4022988505747, 75.4022988505747, 74.4827586206897, 74.4827586206897,
73.5632183908046, 73.5632183908046, 72.6436781609195, 72.6436781609195,
71.7241379310345, 71.7241379310345, 70.8045977011494, 69.8850574712644,
68.9655172413793, 68.9655172413793, 68.0459770114942, 68.0459770114942,
67.1264367816092, 67.1264367816092, 66.2068965517241, 66.2068965517241,
65.2873563218391, 65.2873563218391, 64.367816091954, 64.367816091954,
63.448275862069, 63.448275862069, 62.5287356321839, 62.5287356321839,
61.6091954022989, 61.6091954022989, 60.6896551724138, 60.6896551724138,
59.7701149425287, 59.7701149425287, 58.8505747126437, 58.8505747126437,
57.9310344827586, 57.9310344827586, 57.0114942528736, 57.0114942528736,
56.0919540229885, 56.0919540229885, 55.1724137931034, 55.1724137931034,
54.2528735632184, 54.2528735632184, 53.3333333333333, 53.3333333333333,
52.4137931034483, 51.4942528735632, 51.4942528735632, 50.5747126436782,
49.6551724137931, 49.6551724137931, 48.735632183908, 48.735632183908,
47.816091954023, 47.816091954023, 46.8965517241379, 46.8965517241379,
45.9770114942529, 45.9770114942529, 45.0574712643678, 45.0574712643678,
44.1379310344828, 44.1379310344828, 43.2183908045977, 43.2183908045977,
42.2988505747126, 42.2988505747126, 41.3793103448276, 41.3793103448276,
40.4597701149425, 40.4597701149425, 39.5402298850575, 39.5402298850575,
38.6206896551724, 38.6206896551724, 37.7011494252874, 37.7011494252874,
36.7816091954023, 36.7816091954023, 35.8620689655172, 35.8620689655172,
34.9425287356322, 34.0229885057471, 33.1034482758621, 32.183908045977,
31.2643678160919, 30.3448275862069, 30.3448275862069, 29.4252873563218,
29.4252873563218, 28.5057471264368, 28.5057471264368, 27.5862068965517,
27.5862068965517, 26.6666666666667, 26.6666666666667, 25.7471264367816,
25.7471264367816, 24.8275862068965, 24.8275862068965, 23.9080459770115,
23.9080459770115, 22.9885057471264, 22.0689655172414, 21.1494252873563,
20.2298850574713, 19.3103448275862, 18.3908045977012, 17.4712643678161,
16.551724137931, 15.632183908046, 14.7126436781609, 13.7931034482759,
12.8735632183908, 11.9540229885058, 11.0344827586207, 10.1149425287356,
9.19540229885057, 8.27586206896552, 7.35632183908046, 6.43678160919541,
5.51724137931035, 4.59770114942529, 3.67816091954023, 2.75862068965517,
1.83908045977012, 0.919540229885058, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1.89655172413793, 3.79310344827586,
5.68965517241379, 7.58620689655172, 9.48275862068966, 11.3793103448276,
13.2758620689655, 15.1724137931034, 17.0689655172414, 18.9655172413793,
20.8620689655172, 22.7586206896552, 24.6551724137931, 26.551724137931,
28.448275862069, 30.3448275862069, 30.3448275862069, 32.2413793103448,
34.1379310344828, 36.0344827586207, 37.9310344827586, 39.8275862068966,
41.7241379310345, 43.6206896551724, 45.5172413793103, 47.4137931034483,
49.3103448275862, 51.2068965517241, 51.2068965517241, 53.1034482758621,
53.1034482758621, 54.5769230769231, 54.1538461538462, 54.1538461538462,
53.7307692307692, 53.7307692307692, 53.3076923076923, 53.3076923076923,
52.8846153846154, 52.8846153846154, 52.4615384615385, 52.4615384615385,
52.0384615384615, 51.6153846153846, 51.6153846153846, 51.1923076923077,
51.1923076923077, 50.7692307692308, 50.7692307692308, 50.3461538461538,
50.3461538461538, 49.9230769230769, 49.9230769230769, 49.5, 49.5,
49.0769230769231, 49.0769230769231, 48.6538461538462, 48.6538461538462,
48.2307692307692, 47.8076923076923, 47.3846153846154, 46.9615384615385,
46.5384615384615, 46.1153846153846, 45.6923076923077, 45.6923076923077,
45.2692307692308, 45.2692307692308, 44.8461538461538, 44.8461538461538,
44.4230769230769, 44.4230769230769, 44, 44, 43.5769230769231,
43.5769230769231, 43.1538461538462, 42.7307692307692, 42.7307692307692,
42.3076923076923, 42.3076923076923, 41.8846153846154, 41.8846153846154,
41.4615384615385, 41.4615384615385, 41.0384615384615, 41.0384615384615,
40.6153846153846, 40.6153846153846, 40.1923076923077, 40.1923076923077,
39.7692307692308, 39.7692307692308, 39.3461538461538, 39.3461538461538,
38.9230769230769, 38.9230769230769, 38.5, 38.5, 38.0769230769231,
38.0769230769231, 37.6538461538462, 37.6538461538462, 37.2307692307692,
37.2307692307692, 36.8076923076923, 36.8076923076923, 36.3846153846154,
36.3846153846154, 35.9615384615385, 35.9615384615385, 35.5384615384615,
35.5384615384615, 35.1153846153846, 35.1153846153846, 34.6923076923077,
34.6923076923077, 34.2692307692308, 34.2692307692308, 33.8461538461538,
33.8461538461538, 33.4230769230769, 33.4230769230769, 33, 33,
32.5769230769231, 32.5769230769231, 32.1538461538462, 32.1538461538462,
31.7307692307692, 31.7307692307692, 31.3076923076923, 31.3076923076923,
30.8846153846154, 30.8846153846154, 30.4615384615385, 30.4615384615385,
30.0384615384615, 30.0384615384615, 29.6153846153846, 29.1923076923077,
29.1923076923077, 28.7692307692308, 28.7692307692308, 28.3461538461538,
28.3461538461538, 27.9230769230769, 27.9230769230769, 27.5, 27.5,
27.0769230769231, 27.0769230769231, 26.6538461538462, 26.6538461538462,
26.2307692307692, 26.2307692307692, 25.8076923076923, 25.8076923076923,
25.3846153846154, 25.3846153846154, 24.9615384615385, 24.9615384615385,
24.5384615384615, 24.5384615384615, 24.1153846153846, 24.1153846153846,
23.6923076923077, 23.6923076923077, 23.2692307692308, 23.2692307692308,
22.8461538461538, 22.8461538461538, 22.4230769230769, 22.4230769230769,
22, 22, 21.5769230769231, 21.5769230769231, 21.1538461538462,
21.1538461538462, 20.7307692307692, 20.7307692307692, 20.3076923076923,
20.3076923076923, 19.8846153846154, 19.4615384615385, 19.0384615384615,
18.6153846153846, 18.1923076923077, 17.7692307692308, 17.3461538461538,
16.9230769230769, 16.5, 16.5, 16.0769230769231, 16.0769230769231,
15.6538461538462, 15.6538461538462, 15.2307692307692, 15.2307692307692,
14.8076923076923, 14.8076923076923, 14.3846153846154, 14.3846153846154,
13.9615384615385, 13.9615384615385, 13.5384615384615, 13.5384615384615,
13.1153846153846, 13.1153846153846, 12.6923076923077, 12.6923076923077,
12.2692307692308, 12.2692307692308, 11.8461538461538, 11.8461538461538,
11.4230769230769, 11.4230769230769, 11, 10.5769230769231, 10.5769230769231,
10.1538461538462, 9.73076923076923, 9.30769230769231, 8.88461538461539,
8.46153846153846, 8.03846153846154, 7.61538461538461, 7.19230769230769,
6.76923076923077, 6.34615384615385, 5.92307692307692, 5.5, 5.07692307692308,
4.65384615384615, 4.23076923076923, 3.80769230769231, 3.38461538461539,
2.96153846153846, 2.53846153846153, 2.11538461538461, 1.69230769230769,
1.26923076923077, 0.84615384615384, 0.42307692307692, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0))
Thanks to you for the package and the fix!
When applying
tsoutliers()
to the following time series:and calling
the following indexes are returned and multiple indeces are returned twice (e.g. 307):
Session info
``` R version 3.6.1 (2019-07-05) Platform: x86_64-apple-darwin15.6.0 (64-bit) Running under: macOS Mojave 10.14.6 Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib Random number generation: RNG: Mersenne-Twister Normal: Inversion Sample: Rounding locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] parallel stats graphics grDevices utils datasets methods base other attached packages: [1] timeDate_3043.102 forecastHybrid_4.2.17 thief_0.3 caret_6.0-84 [5] ggplot2_3.2.1 lattice_0.20-38 zoo_1.8-6 prophet_0.5 [9] rlang_0.4.1 Rcpp_1.0.3 tsintermittent_1.9 MAPA_2.0.4 [13] smooth_2.5.4 greybox_0.5.6 RColorBrewer_1.1-2 forecast_8.9 [17] data.table_1.12.6 bigrquery_1.2.0 RPostgreSQL_0.6-2 DBI_1.0.0 loaded via a namespace (and not attached): [1] tseries_0.10-47 httr_1.4.1 bit64_0.9-7 jsonlite_1.6 [5] splines_3.6.1 foreach_1.4.7 prodlim_2019.11.13 StanHeaders_2.19.0 [9] RcppParallel_4.4.4 assertthat_0.2.1 TTR_0.23-5 stats4_3.6.1 [13] ipred_0.9-9 numDeriv_2016.8-1.1 pillar_1.4.2 glue_1.3.1 [17] quadprog_1.5-7 colorspace_1.4-1 recipes_0.1.7 Matrix_1.2-17 [21] plyr_1.8.4 pkgconfig_2.0.3 rstan_2.19.2 purrr_0.3.3 [25] scales_1.1.0 processx_3.4.1 gower_0.2.1 lava_1.6.6 [29] tibble_2.1.3 generics_0.0.2 xgboost_0.90.0.2 withr_2.1.2 [33] urca_1.3-0 lamW_1.3.0 nnet_7.3-12 lazyeval_0.2.2 [37] cli_1.1.0 quantmod_0.4-15 survival_2.44-1.1 magrittr_1.5 [41] crayon_1.3.4 ps_1.3.0 doParallel_1.0.15 nlme_3.1-140 [45] MASS_7.3-51.4 xts_0.11-2 class_7.3-15 pkgbuild_1.0.6 [49] loo_2.1.0 prettyunits_1.0.2 tools_3.6.1 matrixStats_0.55.0 [53] lifecycle_0.1.0 stringr_1.4.0 munsell_0.5.0 callr_3.3.2 [57] compiler_3.6.1 grid_3.6.1 nloptr_1.2.1 iterators_1.0.12 [61] gtable_0.3.0 ModelMetrics_1.2.2 codetools_0.2-16 fracdiff_1.4-2 [65] inline_0.3.15 curl_4.2 reshape2_1.4.3 R6_2.4.1 [69] gridExtra_2.3 lubridate_1.7.4 dplyr_0.8.3 bit_1.1-14 [73] stringi_1.4.3 rpart_4.1-15 tidyselect_0.2.5 lmtest_0.9-37 ```