抱歉,我无法重现您的结果:
输入数据看起来不错:
> print(items)
Date A B C D
1 1-2010 0 0 0 1
2 2-2010 0 0 1 2
3 3-2010 1 1 0 0
这里没有什么意外:
> data_test <- NULL
> print(data_test)
NULL
> for(i in 1:ncol(items)) {
+ col <- ts(items[,i])
+ fit1 <- auto.arima(col, trace=TRUE)
+ fcast <- forecast(fit1,h=12, level=c(90,95))
+ data_test <- cbind(data_test, fcast$lower)
+ }
正如预期的那样,col 包含最后一次调用 ts 的结果:
> print(col)
Time Series:
Start = 1
End = 3
Frequency = 1
[1] 1 2 0
输入数据看起来未受影响:
> print(items)
Date A B C D
1 1-2010 0 0 0 1
2 2-2010 0 0 1 2
3 3-2010 1 1 0 0
和输出:
> print(data_test)
90% 95% 90% 95% 90% 95%
[1,] 0.6569826 0.3996961 -0.7020735 -0.8420231 -0.7020735 -0.8420231
[2,] 0.6569826 0.3996961 -0.3839978 -0.5337011 -0.3839978 -0.5337011
[3,] 0.6569826 0.3996961 -0.5312107 -0.6822689 -0.5312107 -0.6822689
[4,] 0.6569826 0.3996961 -0.4790011 -0.6302537 -0.4790011 -0.6302537
[5,] 0.6569826 0.3996961 -0.4993618 -0.6506425 -0.4993618 -0.6506425
[6,] 0.6569826 0.3996961 -0.4917056 -0.6429903 -0.4917056 -0.6429903
[7,] 0.6569826 0.3996961 -0.4946245 -0.6459098 -0.4946245 -0.6459098
[8,] 0.6569826 0.3996961 -0.4935175 -0.6448029 -0.4935175 -0.6448029
[9,] 0.6569826 0.3996961 -0.4939381 -0.6452235 -0.4939381 -0.6452235
[10,] 0.6569826 0.3996961 -0.4937784 -0.6450638 -0.4937784 -0.6450638
[11,] 0.6569826 0.3996961 -0.4938391 -0.6451245 -0.4938391 -0.6451245
[12,] 0.6569826 0.3996961 -0.4938160 -0.6451014 -0.4938160 -0.6451014
90% 95% 90% 95%
[1,] -0.9496567 -1.131586 1.42604280 1.27350002
[2,] -0.9496567 -1.131586 -0.64967538 -0.84765489
[3,] -0.9496567 -1.131586 0.73647195 0.51264884
[4,] -0.9496567 -1.131586 -0.60589544 -0.84580765
[5,] -0.9496567 -1.131586 0.38080673 0.13047778
[6,] -0.9496567 -1.131586 -0.51643718 -0.77365275
[7,] -0.9496567 -1.131586 0.17206486 -0.08975985
[8,] -0.9496567 -1.131586 -0.43367240 -0.69860560
[9,] -0.9496567 -1.131586 0.04304077 -0.22399916
[10,] -0.9496567 -1.131586 -0.36792524 -0.63639759
[11,] -0.9496567 -1.131586 -0.03920847 -0.30865684
[12,] -0.9496567 -1.131586 -0.31885153 -0.58896591
唯一的问题是您可能应该省略第一列 (for(i in 2:ncol(items))) 因为拟合日期标签有点毫无意义,不是吗?