我花了很多时间,而且我认为我无处可去。我尝试在predict
方法中使用预测区间。在这里,我试图根据从日志返回生成的AR模型来预测日志返回的未来值。
> model_1 <- ar(data1[,'Log Return'], aic = TRUE, order.max = NULL, method = c("mle"))
> predict(model_1, data1[,'Log Return'], n.ahead = 8, level = 0.95, interval = "prediction")
但是,R拒绝在输出中给出任何预测间隔:
$pred
Time Series:
Start = 264
End = 271
Frequency = 1
[1] 0.005904645 0.006259840 0.007770717 0.007785322 0.007944444 0.007832193 0.007811966 0.007772691
$se
Time Series:
Start = 264
End = 271
Frequency = 1
[1] 0.009038997 0.009569202 0.009830485 0.009831987 0.009831988 0.009834717 0.009835227 0.009835437
我到处搜索都无济于事,我开始怀疑predict
方法不能给出AR模型的预测间隔。
答案 0 :(得分:1)
由于我们没有您的数据,因此我将使用ar
帮助文件中的模型进行预测。您不希望predict
用于预测间隔。使用n.ahead
中的ar
参数,并从forecast
包中获取预测间隔。
> (sunspot.ar <- ar(sunspot.year, n.ahead = 8))
Call:
ar(x = sunspot.year, n.ahead = 8)
Coefficients:
1 2 3 4 5 6 7 8 9
1.1305 -0.3524 -0.1745 0.1403 -0.1358 0.0963 -0.0556 0.0076 0.1941
Order selected 9 sigma^2 estimated as 267.5
> library(forecast)
> forecast(sunspot.ar, levels = 95)
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
1989 135.25933 114.299317 156.21935 103.203755 167.31491
1990 148.09051 116.455825 179.72519 99.709436 196.47158
1991 133.98476 96.875479 171.09404 77.231012 190.73851
1992 106.61344 68.200200 145.02667 47.865460 165.36141
1993 71.21921 32.673811 109.76461 12.269108 130.16932
1994 40.84057 2.193737 79.48741 -18.264662 99.94581
1995 18.70100 -20.206540 57.60853 -40.802945 78.20494
1996 11.52416 -27.675854 50.72418 -48.427088 71.47541
1997 27.24208 -12.115656 66.59982 -32.950383 87.43454
1998 56.99888 17.600443 96.39731 -3.255828 117.25359