如何捕获复杂的季节性(MSTS对象)

时间:2019-05-13 10:04:30

标签: r forecasting forecast

我有一个数据集,其中两列(日期和收入)。第一列包含日期(以charecter表示),实际上它仅是一周,一月或一年中的工作日。换句话说,这些只是每天的工作日数据。

 str(TEST_SET)  
  Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 740 obs. of  2 variables:
 $ date   : chr  "04.1.2016" "05.1.2016" "08.1.2016" "11.1.2016" ...
 $ revenue: num  92 496 254 51 172 204 69 737 80 87 ...

在这里,我的意图是使用某些单变量模型(如TBATS或STL + ETS)从包Forecast()中进行预测。但是,这里我的问题是如何处理复杂的季节性,或更准确地说,如何在msts对象中正确设置Season.period,这是上述模型中输入的。

 TEST_SET<- structure(list(date = c("04.1.2016", "05.1.2016", "08.1.2016", 
    "11.1.2016", "12.1.2016", "13.1.2016", "14.1.2016", "15.1.2016", 
    "18.1.2016", "20.1.2016", "21.1.2016", "22.1.2016", "25.1.2016", 
    "26.1.2016", "27.1.2016", "28.1.2016", "29.1.2016", "01.2.2016", 
    "02.2.2016", "03.2.2016", "04.2.2016", "05.2.2016", "08.2.2016", 
    "09.2.2016", "10.2.2016", "11.2.2016", "12.2.2016", "15.2.2016", 
    "16.2.2016", "17.2.2016", "18.2.2016", "19.2.2016", "22.2.2016", 
    "23.2.2016", "24.2.2016", "25.2.2016", "26.2.2016", "29.2.2016", 
    "01.3.2016", "02.3.2016", "03.3.2016", "04.3.2016", "07.3.2016", 
    "08.3.2016", "09.3.2016", "10.3.2016", "11.3.2016", "14.3.2016", 
    "15.3.2016", "16.3.2016", "17.3.2016", "18.3.2016", "21.3.2016", 
    "22.3.2016", "23.3.2016", "24.3.2016", "25.3.2016", "28.3.2016", 
    "29.3.2016", "30.3.2016", "31.3.2016", "01.4.2016", "04.4.2016", 
    "05.4.2016", "06.4.2016", "07.4.2016", "08.4.2016", "11.4.2016", 
    "12.4.2016", "13.4.2016", "14.4.2016", "15.4.2016", "18.4.2016", 
    "19.4.2016", "20.4.2016", "21.4.2016", "22.4.2016", "25.4.2016", 
    "26.4.2016", "27.4.2016", "28.4.2016", "03.5.2016", "04.5.2016", 
    "05.5.2016", "06.5.2016", "09.5.2016", "10.5.2016", "11.5.2016", 
    "12.5.2016", "13.5.2016", "16.5.2016", "17.5.2016", "18.5.2016", 
    "19.5.2016", "20.5.2016", "23.5.2016", "25.5.2016", "26.5.2016", 
    "27.5.2016", "30.5.2016", "31.5.2016", "01.6.2016", "02.6.2016", 
    "03.6.2016", "06.6.2016", "07.6.2016", "08.6.2016", "09.6.2016", 
    "10.6.2016", "13.6.2016", "14.6.2016", "15.6.2016", "16.6.2016", 
    "20.6.2016", "21.6.2016", "22.6.2016", "23.6.2016", "24.6.2016", 
    "27.6.2016", "28.6.2016", "29.6.2016", "30.6.2016", "01.7.2016", 
    "04.7.2016", "06.7.2016", "07.7.2016", "08.7.2016", "11.7.2016", 
    "12.7.2016", "13.7.2016", "14.7.2016", "15.7.2016", "18.7.2016", 
    "19.7.2016", "20.7.2016", "21.7.2016", "22.7.2016", "25.7.2016", 
    "26.7.2016", "27.7.2016", "28.7.2016", "29.7.2016", "01.8.2016", 
    "03.8.2016", "04.8.2016", "05.8.2016", "08.8.2016", "09.8.2016", 
    "10.8.2016", "11.8.2016", "12.8.2016", "15.8.2016", "16.8.2016", 
    "17.8.2016", "18.8.2016", "19.8.2016", "22.8.2016", "23.8.2016", 
    "24.8.2016", "25.8.2016", "26.8.2016", "29.8.2016", "30.8.2016", 
    "31.8.2016", "01.9.2016", "02.9.2016", "05.9.2016", "06.9.2016", 
    "07.9.2016", "09.9.2016", "12.9.2016", "13.9.2016", "14.9.2016", 
    "15.9.2016", "16.9.2016", "19.9.2016", "20.9.2016", "21.9.2016", 
    "22.9.2016", "23.9.2016", "26.9.2016", "27.9.2016", "28.9.2016", 
    "29.9.2016", "30.9.2016", "03.10.2016", "04.10.2016", "05.10.2016", 
    "06.10.2016", "07.10.2016", "10.10.2016", "12.10.2016", "13.10.2016", 
    "14.10.2016", "17.10.2016", "18.10.2016", "19.10.2016", "20.10.2016", 
    "21.10.2016", "25.10.2016", "26.10.2016", "27.10.2016", "28.10.2016", 
    "31.10.2016", "01.11.2016", "02.11.2016", "03.11.2016", "04.11.2016", 
    "07.11.2016", "08.11.2016", "09.11.2016", "10.11.2016", "11.11.2016", 
    "14.11.2016", "15.11.2016", "16.11.2016", "17.11.2016", "18.11.2016", 
    "21.11.2016", "22.11.2016", "23.11.2016", "24.11.2016", "25.11.2016", 
    "28.11.2016", "29.11.2016", "30.11.2016", "01.12.2016", "02.12.2016", 
    "05.12.2016", "06.12.2016", "07.12.2016", "09.12.2016", "12.12.2016", 
    "13.12.2016", "14.12.2016", "15.12.2016", "16.12.2016", "19.12.2016", 
    "20.12.2016", "21.12.2016", "22.12.2016", "23.12.2016", "26.12.2016", 
    "27.12.2016", "28.12.2016", "29.12.2016", "30.12.2016", "03.1.2017", 
    "04.1.2017", "05.1.2017", "09.1.2017", "10.1.2017", "11.1.2017", 
    "12.1.2017", "13.1.2017", "16.1.2017", "17.1.2017", "18.1.2017", 
    "20.1.2017", "23.1.2017", "24.1.2017", "25.1.2017", "26.1.2017", 
    "27.1.2017", "30.1.2017", "31.1.2017", "01.2.2017", "02.2.2017", 
    "03.2.2017", "06.2.2017", "07.2.2017", "08.2.2017", "09.2.2017", 
    "10.2.2017", "13.2.2017", "14.2.2017", "15.2.2017", "16.2.2017", 
    "17.2.2017", "20.2.2017", "21.2.2017", "22.2.2017", "23.2.2017", 
    "24.2.2017", "27.2.2017", "28.2.2017", "01.3.2017", "02.3.2017", 
    "03.3.2017", "06.3.2017", "07.3.2017", "08.3.2017", "09.3.2017", 
    "10.3.2017", "13.3.2017", "14.3.2017", "15.3.2017", "16.3.2017", 
    "17.3.2017", "20.3.2017", "21.3.2017", "22.3.2017", "23.3.2017", 
    "24.3.2017", "27.3.2017", "28.3.2017", "29.3.2017", "30.3.2017", 
    "31.3.2017", "03.4.2017", "04.4.2017", "05.4.2017", "06.4.2017", 
    "07.4.2017", "10.4.2017", "11.4.2017", "12.4.2017", "13.4.2017", 
    "18.4.2017", "19.4.2017", "20.4.2017", "21.4.2017", "24.4.2017", 
    "25.4.2017", "26.4.2017", "27.4.2017", "28.4.2017", "02.5.2017", 
    "03.5.2017", "04.5.2017", "05.5.2017", "08.5.2017", "09.5.2017", 
    "10.5.2017", "11.5.2017", "12.5.2017", "15.5.2017", "16.5.2017", 
    "17.5.2017", "18.5.2017", "19.5.2017", "22.5.2017", "23.5.2017", 
    "25.5.2017", "26.5.2017", "29.5.2017", "30.5.2017", "31.5.2017", 
    "01.6.2017", "05.6.2017", "06.6.2017", "07.6.2017", "08.6.2017", 
    "09.6.2017", "12.6.2017", "13.6.2017", "14.6.2017", "15.6.2017", 
    "16.6.2017", "19.6.2017", "20.6.2017", "21.6.2017", "22.6.2017", 
    "23.6.2017", "27.6.2017", "28.6.2017", "29.6.2017", "30.6.2017", 
    "03.7.2017", "04.7.2017", "05.7.2017", "06.7.2017", "07.7.2017", 
    "10.7.2017", "11.7.2017", "12.7.2017", "13.7.2017", "14.7.2017", 
    "17.7.2017", "18.7.2017", "19.7.2017", "20.7.2017", "21.7.2017", 
    "24.7.2017", "25.7.2017", "26.7.2017", "27.7.2017", "28.7.2017", 
    "31.7.2017", "01.8.2017", "03.8.2017", "04.8.2017", "07.8.2017", 
    "08.8.2017", "09.8.2017", "10.8.2017", "11.8.2017", "14.8.2017", 
    "15.8.2017", "16.8.2017", "17.8.2017", "18.8.2017", "21.8.2017", 
    "22.8.2017", "23.8.2017", "24.8.2017", "25.8.2017", "29.8.2017", 
    "30.8.2017", "31.8.2017", "01.9.2017", "04.9.2017", "05.9.2017", 
    "06.9.2017", "07.9.2017", "11.9.2017", "12.9.2017", "13.9.2017", 
    "14.9.2017", "15.9.2017", "18.9.2017", "19.9.2017", "20.9.2017", 
    "21.9.2017", "22.9.2017", "25.9.2017", "26.9.2017", "27.9.2017", 
    "28.9.2017", "29.9.2017", "02.10.2017", "03.10.2017", "04.10.2017", 
    "05.10.2017", "06.10.2017", "09.10.2017", "10.10.2017", "12.10.2017", 
    "13.10.2017", "16.10.2017", "17.10.2017", "18.10.2017", "19.10.2017", 
    "20.10.2017", "24.10.2017", "25.10.2017", "26.10.2017", "27.10.2017", 
    "30.10.2017", "31.10.2017", "01.11.2017", "02.11.2017", "03.11.2017", 
    "06.11.2017", "07.11.2017", "08.11.2017", "09.11.2017", "10.11.2017", 
    "13.11.2017", "14.11.2017", "15.11.2017", "16.11.2017", "17.11.2017", 
    "20.11.2017", "21.11.2017", "22.11.2017", "23.11.2017", "24.11.2017", 
    "27.11.2017", "28.11.2017", "29.11.2017", "30.11.2017", "01.12.2017", 
    "04.12.2017", "05.12.2017", "06.12.2017", "07.12.2017", "11.12.2017", 
    "12.12.2017", "13.12.2017", "14.12.2017", "15.12.2017", "18.12.2017", 
    "19.12.2017", "20.12.2017", "21.12.2017", "22.12.2017", "25.12.2017", 
    "26.12.2017", "27.12.2017", "28.12.2017", "29.12.2017", "02.1.2018", 
    "03.1.2018", "04.1.2018", "05.1.2018", "09.1.2018", "10.1.2018", 
    "11.1.2018", "12.1.2018", "15.1.2018", "16.1.2018", "17.1.2018", 
    "18.1.2018", "22.1.2018", "23.1.2018", "24.1.2018", "25.1.2018", 
    "26.1.2018", "29.1.2018", "30.1.2018", "31.1.2018", "01.2.2018", 
    "02.2.2018", "05.2.2018", "06.2.2018", "07.2.2018", "08.2.2018", 
    "09.2.2018", "12.2.2018", "13.2.2018", "14.2.2018", "15.2.2018", 
    "16.2.2018", "19.2.2018", "20.2.2018", "21.2.2018", "22.2.2018", 
    "23.2.2018", "26.2.2018", "27.2.2018", "28.2.2018", "01.3.2018", 
    "02.3.2018", "05.3.2018", "06.3.2018", "07.3.2018", "08.3.2018", 
    "09.3.2018", "12.3.2018", "13.3.2018", "14.3.2018", "15.3.2018", 
    "16.3.2018", "19.3.2018", "20.3.2018", "21.3.2018", "22.3.2018", 
    "23.3.2018", "26.3.2018", "27.3.2018", "28.3.2018", "29.3.2018", 
    "30.3.2018", "02.4.2018", "03.4.2018", "04.4.2018", "05.4.2018", 
    "10.4.2018", "11.4.2018", "12.4.2018", "13.4.2018", "16.4.2018", 
    "17.4.2018", "18.4.2018", "19.4.2018", "20.4.2018", "23.4.2018", 
    "24.4.2018", "25.4.2018", "26.4.2018", "27.4.2018", "30.4.2018", 
    "02.5.2018", "03.5.2018", "04.5.2018", "07.5.2018", "08.5.2018", 
    "09.5.2018", "10.5.2018", "11.5.2018", "14.5.2018", "15.5.2018", 
    "16.5.2018", "17.5.2018", "18.5.2018", "21.5.2018", "22.5.2018", 
    "23.5.2018", "28.5.2018", "29.5.2018", "30.5.2018", "31.5.2018", 
    "01.6.2018", "04.6.2018", "05.6.2018", "06.6.2018", "07.6.2018", 
    "08.6.2018", "11.6.2018", "12.6.2018", "13.6.2018", "14.6.2018", 
    "18.6.2018", "19.6.2018", "20.6.2018", "21.6.2018", "22.6.2018", 
    "25.6.2018", "26.6.2018", "27.6.2018", "28.6.2018", "29.6.2018", 
    "02.7.2018", "03.7.2018", "04.7.2018", "05.7.2018", "06.7.2018", 
    "09.7.2018", "10.7.2018", "11.7.2018", "12.7.2018", "13.7.2018", 
    "16.7.2018", "17.7.2018", "18.7.2018", "19.7.2018", "20.7.2018", 
    "23.7.2018", "24.7.2018", "25.7.2018", "26.7.2018", "27.7.2018", 
    "30.7.2018", "31.7.2018", "01.8.2018", "03.8.2018", "06.8.2018", 
    "07.8.2018", "08.8.2018", "09.8.2018", "10.8.2018", "13.8.2018", 
    "14.8.2018", "15.8.2018", "16.8.2018", "17.8.2018", "20.8.2018", 
    "21.8.2018", "22.8.2018", "23.8.2018", "24.8.2018", "27.8.2018", 
    "29.8.2018", "30.8.2018", "31.8.2018", "03.9.2018", "04.9.2018", 
    "05.9.2018", "06.9.2018", "07.9.2018", "10.9.2018", "11.9.2018", 
    "12.9.2018", "13.9.2018", "14.9.2018", "17.9.2018", "18.9.2018", 
    "19.9.2018", "20.9.2018", "21.9.2018", "24.9.2018", "25.9.2018", 
    "26.9.2018", "27.9.2018", "28.9.2018", "01.10.2018", "02.10.2018", 
    "03.10.2018", "04.10.2018", "05.10.2018", "08.10.2018", "09.10.2018", 
    "10.10.2018", "12.10.2018", "15.10.2018", "16.10.2018", "17.10.2018", 
    "18.10.2018", "19.10.2018", "22.10.2018", "24.10.2018", "25.10.2018", 
    "26.10.2018", "29.10.2018", "30.10.2018", "31.10.2018", "01.11.2018", 
    "02.11.2018", "05.11.2018", "06.11.2018", "07.11.2018", "08.11.2018", 
    "09.11.2018", "12.11.2018", "13.11.2018", "14.11.2018", "15.11.2018", 
    "16.11.2018", "19.11.2018", "20.11.2018", "21.11.2018", "22.11.2018", 
    "23.11.2018", "26.11.2018", "27.11.2018", "28.11.2018", "29.11.2018", 
    "30.11.2018", "03.12.2018", "04.12.2018", "05.12.2018", "06.12.2018", 
    "07.12.2018", "10.12.2018", "11.12.2018", "12.12.2018", "13.12.2018", 
    "14.12.2018", "17.12.2018", "18.12.2018", "19.12.2018", "20.12.2018", 
    "21.12.2018", "24.12.2018", "25.12.2018", "26.12.2018", "27.12.2018", 
    "28.12.2018", "31.12.2018"), revenue = c(92, 496, 254, 51, 172, 
    204, 69, 737, 80, 87, 28, 255, 38, 21, 11, 27, 136, 203, 404, 
    20, 26, 323, 50, 72, 41, 75, 125, 723, 88, 56, 53, 53, 112, 59, 
    41, 85, 63, 55, 164, 288, 63, 537, 92, 169, 64, 144, 45, 83, 
    464, 46, 73, 32, 55, 126, 59, 74, 175, 148, 217, 53, 57, 51, 
    586, 266, 165, 54, 78, 69, 127, 103, 103, 826, 80, 58, 66, 36, 
    61, 58, 87, 118, 303, 243, 557, 278, 76, 187, 155, 83, 638, 519, 
    186, 51, 76, 68, 75, 107, 63, 71, 66, 284, 59, 150, 368, 462, 
    48, 70, 156, 172, 220, 87, 99, 686, 70, 85, 89, 45, 56, 116, 
    117, 64, 64, 53, 86, 236, 570, 118, 80, 229, 61, 232, 119, 558, 
    81, 142, 66, 85, 78, 182, 129, 97, 92, 277, 203, 708, 360, 302, 
    149, 107, 83, 28, 98, 756, 95, 512, 231, 96, 109, 79, 181, 87, 
    71, 112, 107, 69, 633, 442, 166, 73, 206, 30, 84, 850, 223, 567, 
    101, 30, 84, 135, 148, 75, 105, 115, 358, 119, 95, 129, 541, 
    315, 112, 139, 99, 86, 104, 532, 145, 152, 467, 113, 141, 48, 
    182, 27, 112, 80, 404, 72, 283, 312, 221, 57, 70, 77, 114, 84, 
    541, 276, 92, 87, 67, 77, 149, 97, 104, 79, 98, 14, 241, 242, 
    156, 406, 82, 111, 104, 88, 194, 401, 91, 332, 77, 133, 62, 27, 
    255, 64, 121, 102, 340, 303, 88, 90, 48, 80, 28, 281, 257, 315, 
    54, 58, 434, 67, 40, 48, 56, 63, 49, 70, 113, 305, 268, 302, 
    32, 39, 45, 123, 46, 128, 631, 92, 94, 74, 44, 37, 49, 34, 94, 
    49, 189, 75, 539, 71, 135, 119, 460, 52, 287, 63, 498, 39, 84, 
    58, 71, 84, 70, 74, 85, 53, 69, 68, 168, 622, 420, 61, 93, 237, 
    71, 71, 117, 382, 386, 131, 113, 131, 78, 126, 89, 81, 95, 404, 
    183, 78, 119, 844, 98, 16, 297, 319, 472, 299, 97, 99, 100, 130, 
    180, 223, 130, 85, 73, 0, 138, 124, 764, 263, 95, 91, 64, 53, 
    68, 583, 82, 90, 21, 78, 162, 153, 119, 93, 242, 88, 107, 87, 
    218, 74, 657, 101, 53, 269, 111, 566, 182, 159, 89, 86, 122, 
    98, 80, 175, 76, 392, 82, 694, 333, 760, 226, 98, 184, 90, 142, 
    197, 726, 157, 83, 374, 93, 91, 89, 101, 131, 99, 81, 189, 1097, 
    76, 75, 110, 241, 111, 87, 153, 116, 874, 67, 96, 145, 67, 94, 
    56, 57, 77, 50, 352, 337, 548, 251, 499, 160, 75, 93, 76, 517, 
    143, 112, 376, 194, 169, 100, 21, 103, 105, 237, 54, 494, 194, 
    356, 364, 42, 52, 94, 93, 78, 14, 807, 117, 172, 94, 59, 473, 
    15, 115, 27, 75, 81, 65, 601, 642, 66, 156, 33, 103, 86, 67, 
    21, 511, 87, 227, 74, 83, 36, 24, 121, 72, 140, 65, 76, 493, 
    450, 103, 241, 92, 74, 231, 564, 103, 131, 183, 90, 73, 77, 102, 
    65, 62, 106, 196, 44, 528, 74, 406, 104, 206, 102, 97, 133, 92, 
    406, 394, 70, 9, 117, 161, 26, 72, 22, 143, 75, 333, 103, 822, 
    112, 154, 100, 198, 75, 147, 719, 125, 78, 81, 85, 89, 70, 68, 
    13, 99, 101, 387, 134, 337, 277, 356, 92, 91, 203, 315, 389, 
    127, 428, 109, 222, 27, 19, 252, 33, 188, 118, 120, 546, 191, 
    97, 87, 81, 395, 252, 111, 672, 88, 109, 229, 24, 213, 41, 109, 
    23, 466, 212, 23, 294, 79, 157, 166, 312, 132, 248, 232, 596, 
    156, 126, 107, 147, 184, 21, 182, 16, 12, 877, 78, 75, 174, 332, 
    48, 165, 121, 224, 50, 754, 182, 36, 71, 42, 196, 105, 107, 122, 
    137, 180, 371, 146, 857, 28, 168, 132, 669, 221, 107, 113, 420, 
    712, 240, 250, 130, 103, 104, 149, 203, 132, 228, 119, 222, 147, 
    423, 827, 198, 132, 111, 140, 100, 88, 921, 207, 94, 118, 108, 
    93, 91, 80, 82, 72, 271, 380, 77, 157, 28, 225, 33, 232, 498, 
    466, 601, 103, 101, 108, 138, 115, 123, 85, 27, 228, 88, 130, 
    458, 672, 135, 151, 95, 71, 91, 328, 80, 114, 606, 292, 108, 
    71, 19, 68, 544, 210, 21, 24, 21, 217, 34, 195, 120, 329, 510, 
    54, 170, 114, 86, 557, 201, 309, 99, 96, 102, 110, 27, 115, 116, 
    114, 259)), row.names = c(NA, -740L), class = c("tbl_df", "tbl", 
    "data.frame"))

我尝试下面的代码。首先我找到了频率,然后创建了msts对象,但是在这里我不确定我的方法是否正确?我的每日数据包含2016年,2017年和2018年的三年时间,所以我认为还缺少一些内容吗? 那么有人可以帮助我如何正确地创建msts对象以捕获此数据帧TEST_SET中的各种季节性信息吗?

findfrequency(TEST_SET$revenue)
#> [1] 10

TEST_DAILY<-msts(TEST_SET$revenue,seasonal.periods = c(10))

enter image description here

0 个答案:

没有答案