多个时间序列的Auto Arima

时间:2017-08-15 10:00:10

标签: r

我有多个产品的每周(2015年1月至2017年4月)销售数据。我正在尝试使用Auto Arima来预测未来。对于许多产品,我一直在输出NA。 这是我的示例代码。你可以帮我解决我在代码中出错的地方。

Data1 <- ts(R_Input_Stats[,-1],f=52,s=2015+2/52)
h <- 25
ns <- ncol(Data1)
arimaforecast <- matrix(NA, nrow=h, ncol=ns)
for (i in 1:ns){
  arimaforecast[,i] <- forecast(auto.arima(Data1[,i]), h=h,)$mean}
write(t(arimaforecast),file="R_Output_Stats_ArimaAllSKus.csv",sep=",",ncol=ncol(arimaforecast))

您是否也可以替换上面的&#34; for循环&#34;和&#34; lapply&#34;?如果我想了解每种产品的Auto Arima的顺序? 感谢您的回复 样本数据 样本数据

structure(c(65L, 195L, 110L, 58L, 0L, 273L, 45L, 36L, 15L, 11L, 
10L, 27L, 36L, 16L, 29L, 155L, 22L, 182L, 156L, 528L, 63L, 94L, 
168L, 171L, 197L, 130L, 235L, 19L, 241L, 134L, 466L, 227L, 302L, 
134L, 369L, 405L, 1L, 32L, 5L, 2L, 3L, 0L, 14L, 2011L, 685L, 
629L, 417L, 1086L, 9L, 7L, 6L, 5L, 21L, 10L, 119L, 158L, 128L, 
85L, 153L, 172L, 0L, 0L, 52L, 312L, 0L, 52L, 0L, 0L, 0L, 0L, 
0L, 0L, 19L, 11L, 23L, 16L, 11L, 11L, 12L, 9L, 13L, 20L, 4L, 
20L, 424L, 311L, 1384L, 259L, 581L, 1690L, 195L, 155L, 141L, 
199L, 360L, 316L, 202L, 384L, 322L, 285L, 1643L, 1437L, 101L, 
66L, 294L, 120L, 480L, 204L, 660L, 1100L, 176L, 3933L, 2431L, 
22568L, 16L, 20L, 14L, 25L, 24L, 24L, 0L, 0L, 0L, 0L, 0L, 0L, 
931L, 3586L, 1505L, 794L, 808L, 2750L, 282L, 396L, 247L, 291L, 
666L, 521L, 1576L, 1342L, 1871L, 2084L, 3181L, 3725L, 1161L, 
1431L, 8039L, 5721L, 22688L, 40456L, 803L, 622L, 673L, 915L, 
1142L, 701L, 0L, 0L, 0L, 0L, 0L, 0L, 61L, 0L, 27L, 0L, 216L, 
162L, 26L, 61L, 27L, 33L, 65L, 24L, 161L, 122L, 187L, 115L, 360L, 
227L, 14L, 1L, 2L, 9L, 9L, 6L, 109L, 160L, 297L, 199L, 197L, 
238L, 351L, 324L, 1566L, 336L, 860L, 1715L, 28L, 20L, 53L, 33L, 
59L, 56L, 210L, 420L, 210L, 1050L, 210L, 0L, 9L, 4L, 7L, 9L, 
12L, 17L, 16L, 9L, 29L, 46L, 22L, 171L, 92L, 145L, 125L, 238L, 
126L, 983L, 48L, 26L, 55L, 263L, 199L, 150L, 810L, 129L, 161L, 
211L, 672L, 504L, 30L, 1L, 11L, 2L, 3L, 5L, 0L, 470L, 630L, 1064L, 
1875L, 3350L, 235L, 64L, 135L, 327L, 351L, 471L, 210L, 210L, 
630L, 420L, 840L, 1110L, 0L, 0L, 150L, 75L, 225L, 375L, 68L, 
84L, 88L, 48L, 66L, 116L, 86L, 73L, 54L, 73L, 54L, 85L, 1883L, 
1694L, 1143L, 1325L, 1355L, 2383L, 15L, 27L, 14L, 33L, 132L, 
42L, 2L, 0L, 0L, 1L, 1L, 1L, 2L, 1860L, 3945L, 5165L, 40290L, 
7194L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 14L, 17L, 18L, 77L, 1L, 1119L, 
2533L, 7943L, 2322L, 1298L, 1403L, 41L, 47L, 19L, 39L, 54L, 56L, 
272L, 177L, 290L, 178L, 677L, 1361L, 3808L, 3120L, 18010L, 21026L, 
90002L, 15925L, 72L, 44L, 54L, 74L, 80L, 49L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 40L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 44L, 
211L, 212L, 234L, 219L, 216L, 3L, 3L, 2L, 6L, 1L, 9L, 17L, 5L, 
6L, 12L, 11L, 30L, 0L, 0L, 0L, 0L, 103L, 245L, 0L, 0L, 0L, 0L, 
600L, 480L, 22L, 78L, 57L, 54L, 48L, 93L, 9L, 13L, 10L, 11L, 
7L, 68L, 31L, 23L, 10L, 39L, 12L, 43L, 17L, 2L, 4L, 12L, 3L, 
5L, 39L, 70L, 41L, 36L, 111L, 91L, 0L, 0L, 7L, 39L, 479L, 669L, 
0L, 0L, 0L, 0L, 0L, 0L, 7L, 3L, 8L, 3L, 12L, 9L, 0L, 0L, 0L, 
1L, 0L, 1L, 16L, 17L, 10L, 8L, 14L, 16L, 16L, 16L, 3L, 7L, 48L, 
14L, 120L, 60L, 55L, 36L, 201L, 224L, 15L, 5L, 31L, 5L, 3L, 21L, 
0L, 0L, 0L, 0L, 0L, 90L, 6L, 6L, 11L, 10L, 12L, 10L, 1L, 53L, 
7L, 18L, 6L, 0L, 0L, 0L, 120L, 20L, 120L, 60L, 12L, 3L, 1L, 40L, 
120L, 4L, 9L, 1L, 3L, 9L, 4L, 3L, 22L, 9L, 38L, 44L, 38L, 185L, 
59L, 111L, 238L, 224L, 117L, 445L, 20L, 14L, 20L, 27L, 65L, 41L, 
128L, 50L, 122L, 64L, 208L, 319L, 8L, 8L, 0L, 6L, 0L, 0L, 0L, 
0L, 32L, 587L, 949L, 1155L, 68L, 392L, 39L, 180L, 176L, 92L, 
0L, 120L, 40L, 240L, 400L, 120L, 1027L, 1731L, 3675L, 1493L, 
1896L, 2207L, 0L, 0L, 0L, 0L, 0L, 0L, 541L, 258L, 531L, 376L, 
229L, 324L, 1344L, 0L, 56L, 987L, 4360L, 8701L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 456L, 1864L, 1137L, 670L, 685L, 
1008L, 647L, 329L, 371L, 665L, 552L, 637L, 696L, 448L, 379L, 
451L, 658L, 478L, 560L, 0L, 112L, 199L, 1560L, 2344L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 3366L, 1580L, 2744L, 
616L, 2750L, 2016L, 551L, 264L, 661L, 47L, 1172L, 588L, 7L, 0L, 
4L, 17L, 4L, 23L, 225L, 194L, 120L, 418L, 820L, 237L, 136L, 135L, 
78L, 322L, 467L, 426L, 145L, 58L, 41L, 348L, 216L, 69L, 122L, 
86L, 16L, 90L, 95L, 53L, 10L, 171L, 421L, 66L, 412L, 348L, 221L, 
252L, 807L, 1382L, 38516L, 7962L, 343L, 55L, 28L, 60L, 123L, 
162L, 56L, 168L, 0L, 448L, 182L, 224L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 48L, 0L, 48L, 96L, 242L, 81L, 37L, 13L, 74L, 
320L, 9L, 10L, 3L, 4L, 7L, 64L, 8L, 13L, 12L, 30L, 20L, 13L, 
132L, 750L, 1379L, 110L, 81L, 512L, 195L, 207L, 606L, 171L, 318L, 
847L, 977L, 570L, 839L, 249L, 762L, 1277L, 802L, 81L, 4804L, 
8510L, 4979L, 9953L, 35L, 21L, 24L, 19L, 40L, 35L, 60L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 540L, 0L, 0L, 1L, 
105L, 80L, 64L, 26L, 15L, 141L, 237L, 19L, 63L, 0L, 22L, 99L, 
0L, 0L, 0L, 540L, 3352L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 30L, 17L, 
9L, 8L, 51L, 221L, 1L, 3L, 1L, 0L, 1L, 7L, 26L, 215L, 2L, 26L, 
17L, 23L, 98L, 51L, 52L, 236L, 157L, 113L, 387L, 144L, 150L, 
148L, 622L, 748L, 62L, 12L, 16L, 4L, 11L, 22L, 0L, 0L, 420L, 
0L, 1260L, 23L, 56L, 42L, 79L, 80L, 111L, 67L, 15L, 5L, 2L, 10L, 
19L, 8L, 0L, 270L, 210L, 0L, 210L, 60L, 180L, 37L, 173L, 43L, 
182L, 555L, 45L, 5L, 21L, 121L, 82L, 48L, 132L, 59L, 140L, 72L, 
225L, 750L, 0L, 0L, 0L, 0L, 56L, 223L, 19L, 11L, 23L, 14L, 23L, 
20L, 0L, 131L, 0L, 840L, 210L, 120L, 77L, 89L, 151L, 88L, 188L, 
502L, 12L, 16L, 17L, 19L, 32L, 76L, 307L, 93L, 294L, 154L, 182L, 
992L, 166L, 118L, 108L, 260L, 277L, 136L, 446L, 53L, 132L, 161L, 
717L, 1186L, 0L, 0L, 0L, 358L, 379L, 2000L, 41L, 36L, 46L, 49L, 
74L, 54L, 0L, 61L, 56L, 0L, 50L, 140L, 6L, 6L, 6L, 11L, 21L, 
25L, 3L, 5L, 5L, 0L, 7L, 12L, 16L, 7L, 23L, 8L, 13L, 15L, 26L, 
3L, 4L, 87L, 17L, 31L, 42L, 17L, 13L, 10L, 27L, 30L, 146L, 0L, 
118L, 7L, 4L, 156L, 112L, 0L, 0L, 0L, 49L, 182L, 105L, 101L, 
13L, 23L, 84L, 83L, 0L, 0L, 0L, 0L, 0L, 0L, 611L, 73L, 33L, 355L, 
284L, 1177L, 39L, 8L, 14L, 18L, 29L, 51L, 103L, 47L, 89L, 58L, 
121L, 319L, 0L, 0L, 0L, 0L, 0L, 659L, 289L, 173L, 235L, 355L, 
329L, 1027L, 46L, 24L, 25L, 31L, 89L, 83L, 206L, 207L, 192L, 
99L, 258L, 568L, 440L, 46L, 442L, 0L, 79L, 1456L, 5L, 4L, 2L, 
0L, 5L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 56L, 87L, 25L, 107L, 189L, 
385L, 47L, 18L, 22L, 50L, 47L, 63L, 105L, 88L, 111L, 76L, 195L, 
419L, 0L, 0L, 84L, 76L, 405L, 419L, 301L, 270L, 258L, 448L, 456L, 
964L, 52L, 43L, 39L, 28L, 68L, 143L, 79L, 181L, 83L, 34L, 261L, 
407L, 41L, 17L, 15L, 20L, 20L, 19L, 118L, 43L, 32L, 67L, 79L, 
401L, 300L, 0L, 0L, 64L, 719L, 1883L, 5L, 3L, 4L, 7L, 3L, 7L, 
280L, 160L, 0L, 240L, 840L, 200L, 147L, 303L, 232L, 238L, 524L, 
291L, 44L, 53L, 88L, 94L, 103L, 239L, 33L, 27L, 39L, 37L, 35L, 
51L, 2420L, 1308L, 2561L, 1574L, 8384L, 11439L, 220L, 76L, 162L, 
121L, 228L, 216L, 5083L, 6017L, 5096L, 5055L, 9845L, 27159L, 
7680L, 7720L, 88259L, 31626L, 121167L, 191974L, 3397L, 2470L, 
2578L, 3189L, 4489L, 7246L, 0L, 0L, 0L, 0L, 0L, 0L, 405L, 513L, 
513L, 216L, 1327L, 891L, 389L, 848L, 825L, 643L, 1215L, 437L, 
112L, 106L, 137L, 149L, 179L, 361L, 131L, 83L, 171L, 79L, 151L, 
53L, 1917L, 2333L, 1550L, 3144L, 2094L, 2605L, 440L, 135L, 375L, 
272L, 387L, 408L, 2240L, 2235L, 2975L, 2379L, 3068L, 3653L, 967L, 
1220L, 631L, 332L, 1296L, 1296L, 4666L, 4457L, 37948L, 42699L, 
45697L, 47091L, 1009L, 653L, 687L, 938L, 1296L, 863L, 0L, 0L, 
0L, 0L, 0L, 0L, 634L, 839L, 422L, 711L, 646L, 1129L, 2403L, 1809L, 
2673L, 1377L, 2619L, 3726L), .Dim = c(6L, 213L), .Dimnames = list(
    NULL, c("70-103", "70-110", "70-111", "70-201", "70-202", 
    "70-203", "70-204", "70-210", "70-211", "70-300", "70-303", 
    "365-103", "365-110", "365-111", "365-201", "365-202", "365-203", 
    "365-204", "365-210", "365-211", "365-217", "375-201", "375-202", 
    "375-203", "375-210", "375-211", "375-217", "506-103", "506-110", 
    "506-201", "506-202", "506-203", "506-210", "506-211", "661-103", 
    "661-110", "661-111", "661-201", "661-202", "661-203", "661-204", 
    "661-210", "661-300", "661-303", "673-103", "673-110", "673-111", 
    "673-201", "673-203", "673-204", "673-210", "673-217", "673-300", 
    "697-201", "697-202", "697-203", "697-210", "697-211", "697-217", 
    "14071-103", "14071-111", "14071-201", "14071-202", "14071-203", 
    "14071-210", "33127-103", "33127-110", "33127-111", "33127-201", 
    "33127-202", "33127-203", "33127-210", "33127-217", "33282-110", 
    "33282-111", "33282-201", "33282-202", "33282-203", "33282-204", 
    "33282-210", "33282-211", "33282-300", "33282-303", "33560-103", 
    "33560-110", "33560-111", "33560-201", "33560-202", "33560-203", 
    "33560-204", "33560-210", "33560-300", "33560-303", "48330-201", 
    "48330-202", "48330-203", "48330-210", "48330-211", "48330-217", 
    "48331-201", "48331-202", "48331-203", "48331-210", "48331-211", 
    "48331-217", "48372-103", "48372-110", "48372-111", "48372-123", 
    "48372-201", "48372-202", "48372-203", "48372-204", "48372-210", 
    "48372-300", "48372-303", "52033-201", "52033-202", "52033-203", 
    "52033-210", "1002101-103", "1002101-110", "1002101-111", 
    "1002101-123", "1002101-201", "1002101-202", "1002101-203", 
    "1002101-210", "1002101-211", "1002102-103", "1002102-110", 
    "1002102-201", "1002102-202", "1002102-203", "1002102-210", 
    "1002117-103", "1002117-110", "1002117-111", "1002117-201", 
    "1002117-202", "1002117-203", "1002117-204", "1002117-210", 
    "1002117-211", "1002117-300", "1002117-303", "1004101-201", 
    "1004101-202", "1004101-203", "1004101-210", "1004101-211", 
    "1004117-103", "1004117-110", "1004117-111", "1004117-201", 
    "1004117-202", "1004117-203", "1004117-210", "1004117-211", 
    "1005101-103", "1005101-110", "1005101-111", "1005101-201", 
    "1005101-202", "1005101-203", "1005101-204", "1005101-210", 
    "1005101-300", "1005101-303", "1010101-201", "1010101-202", 
    "1010101-203", "1010101-210", "1049101-201", "1049101-202", 
    "1049101-203", "1049101-210", "1049101-211", "1049101-217", 
    "1049117-201", "1049117-202", "1049117-203", "1049117-210", 
    "1104102-110", "1104102-111", "1104102-201", "1104102-202", 
    "1104102-203", "1104102-210", "1104102-211", "1420124-103", 
    "1420124-110", "1420124-111", "1420124-123", "1420124-201", 
    "1420124-202", "1420124-203", "1420124-210", "1420124-211", 
    "1420124-217", "1420133-103", "1420133-110", "1420133-111", 
    "1420133-123", "1420133-201", "1420133-202", "1420133-203", 
    "1420133-204", "1420133-210", "1420133-211", "1420133-217", 
    "1420133-300", "1420133-303")), .Tsp = c(2015.03846153846, 
2015.13461538462, 52), class = c("mts", "ts", "matrix"))

0 个答案:

没有答案