我应用了auto.arima
包中的forecast
函数,为时间序列mdl_1
找到了最适合的模型x
:
library(forecast)
x <- c(437, 403, 390, 398, 401, 396, 420, 472, 501, 508, 495, 488,
458, 484, 434, 430, 469, 431, 403, 391, 401, 427, 424, 445, 449,
429, 429, 413, 417, 390, 375, 438, 435, 446, 448, 452, 436, 438,
470, 437, 428, 406, 409, 416, 439, 440, 498, 527, 481, 461, 431,
405, 398, 409, 425, 475, 503, 531, 510, 484, 490, 455, 468, 438,
469, 527, 489, 448, 448, 483, 547, 524)
mdl_1 <- auto.arima(x)
mdl_2 <- Arima( x, order=c(2,1,2), include.drift=FALSE )
结果如下:
> mdl_1
Series: x
ARIMA(2,1,2) with drift
Coefficients:
ar1 ar2 ma1 ma2 drift
1.5191 -0.7501 -1.6225 0.6780 0.7976
s.e. 0.1773 0.1401 0.2060 0.2075 0.7621
sigma^2 estimated as 597.7: log likelihood=-328.43
AIC=668.87 AICc=670.18 BIC=682.44
mdl_2
属于同一类型,但没有漂移术语:
> mdl_2
Series: x
ARIMA(2,1,2)
Coefficients:
ar1 ar2 ma1 ma2
0.0134 0.4741 -0.0278 -0.8807
s.e. 0.2623 0.2519 0.2112 0.2079
sigma^2 estimated as 628.9: log likelihood=-330.2
AIC=670.4 AICc=671.32 BIC=681.71
mdl_2
可以预测,但mdl_1
不能:
> predict(mdl_2)
$pred
Time Series:
Start = 73
End = 73
Frequency = 1
[1] 495.5033
$se
Time Series:
Start = 73
End = 73
Frequency = 1
[1] 25.07916
> predict(mdl_1)
Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x), :
'data' must be of a vector type, was 'NULL'
>
此错误消息来自何处?
答案 0 :(得分:2)
使用forecast
而非predict
。
> forecast(mdl_1)
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
73 514.0173 482.6868 545.3478 466.1014 561.9332
74 501.9714 459.8902 544.0525 437.6138 566.3289
75 491.3458 444.3540 538.3376 419.4781 563.2135
76 484.4253 435.8153 533.0353 410.0828 558.7679
77 482.0673 433.2062 530.9285 407.3407 556.7940
78 483.8607 434.9996 532.7219 409.1340 558.5874
79 488.5377 439.6323 537.4432 413.7433 563.3321
80 494.4812 445.5567 543.4056 419.6577 569.3047
81 500.1853 451.2454 549.1252 425.3382 575.0325
82 504.5762 455.4176 553.7349 429.3945 579.7579
> forecast(mdl_2)
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
73 495.5033 463.3631 527.6435 446.3490 544.6576
74 496.5058 451.3764 541.6351 427.4864 565.5251
75 483.0090 434.1939 531.8240 408.3528 557.6651
76 483.3028 431.2005 535.4051 403.6192 562.9864
77 476.9079 423.4393 530.3765 395.1347 558.6811
78 476.9613 422.2190 531.7035 393.2402 560.6823
79 473.9302 418.4861 529.3743 389.1357 558.7246
80 473.9147 417.8036 530.0259 388.1001 559.7294
81 472.4775 415.9028 529.0522 385.9540 559.0010
82 472.4508 415.4288 529.4729 385.2431 559.6585
predict
不理解漂移条款。
答案 1 :(得分:0)
如果您使用:
mdl_1 <- auto.arima(x, allowdrift =FALSE)
它适用于mdl_1
如果你使用
mdl_2 <- Arima( x, order=c(2,1,2), include.drift=TRUE )
它不适用于mdl_2
所以它可能与drift