使用 vars 包和 forecast 函数来绘制未来的观察结果
Using vars package and the forecast function to plot future observations
在以下站点 (https://www.otexts.org/fpp/9/2) 上创建了向量自回归。
library(vars)
VARselect(usconsumption, lag.max=8, type="const")$selection
var <- VAR(usconsumption, p=3, type="const")
serial.test(var, lags.pt=10, type="PT.asymptotic")
summary(var)
代码比较简单,但是创建预测时:
fcst <- forecast(var)
plot(fcst, xlab="Year")
forecast
功能不起作用。但是,使用 predict
函数不会生成与预测函数相同的图。
任何建议,如何从提供的情节中获取link?
感谢您的回复!
你是什么意思"the forecast
function does not work"?我得到了你想要的情节,预测函数给出了完全相同的预测:
> fcst <- forecast(var, h=3)
> pred <- predict(var, n.ahead=3)
> fcst
consumption
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2011 Q1 0.7421472 -0.06576279 1.550057 -0.4934445 1.977739
2011 Q2 0.7980532 -0.03433474 1.630441 -0.4749743 2.071081
2011 Q3 0.7921921 -0.06526268 1.649647 -0.5191718 2.103556
income
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2011 Q1 0.8208025 -0.2748906 1.916496 -0.8549154 2.496520
2011 Q2 0.7188650 -0.4437286 1.881459 -1.0591685 2.496898
2011 Q3 0.8241248 -0.3388670 1.987117 -0.9545177 2.602767
> pred
$consumption
fcst lower upper CI
[1,] 0.7421472 -0.4934445 1.977739 1.235592
[2,] 0.7980532 -0.4749743 2.071081 1.273028
[3,] 0.7921921 -0.5191718 2.103556 1.311364
$income
fcst lower upper CI
[1,] 0.8208025 -0.8549154 2.496520 1.675718
[2,] 0.7188650 -1.0591685 2.496898 1.778034
[3,] 0.8241248 -0.9545177 2.602767 1.778643
在以下站点 (https://www.otexts.org/fpp/9/2) 上创建了向量自回归。
library(vars)
VARselect(usconsumption, lag.max=8, type="const")$selection
var <- VAR(usconsumption, p=3, type="const")
serial.test(var, lags.pt=10, type="PT.asymptotic")
summary(var)
代码比较简单,但是创建预测时:
fcst <- forecast(var)
plot(fcst, xlab="Year")
forecast
功能不起作用。但是,使用 predict
函数不会生成与预测函数相同的图。
任何建议,如何从提供的情节中获取link?
感谢您的回复!
你是什么意思"the forecast
function does not work"?我得到了你想要的情节,预测函数给出了完全相同的预测:
> fcst <- forecast(var, h=3)
> pred <- predict(var, n.ahead=3)
> fcst
consumption
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2011 Q1 0.7421472 -0.06576279 1.550057 -0.4934445 1.977739
2011 Q2 0.7980532 -0.03433474 1.630441 -0.4749743 2.071081
2011 Q3 0.7921921 -0.06526268 1.649647 -0.5191718 2.103556
income
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2011 Q1 0.8208025 -0.2748906 1.916496 -0.8549154 2.496520
2011 Q2 0.7188650 -0.4437286 1.881459 -1.0591685 2.496898
2011 Q3 0.8241248 -0.3388670 1.987117 -0.9545177 2.602767
> pred
$consumption
fcst lower upper CI
[1,] 0.7421472 -0.4934445 1.977739 1.235592
[2,] 0.7980532 -0.4749743 2.071081 1.273028
[3,] 0.7921921 -0.5191718 2.103556 1.311364
$income
fcst lower upper CI
[1,] 0.8208025 -0.8549154 2.496520 1.675718
[2,] 0.7188650 -1.0591685 2.496898 1.778034
[3,] 0.8241248 -0.9545177 2.602767 1.778643