【问题标题】:Using vars package and the forecast function to plot future observations使用 vars 包和预测函数来绘制未来的观察结果
【发布时间】:2015-10-08 11:11:04
【问题描述】:

在以下站点 (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获取情节?

感谢您的回复!

【问题讨论】:

    标签: r statistics forecasting


    【解决方案1】:

    forecast 函数不起作用”是什么意思?我得到了你想要的图,并且 predict 函数给出了完全相同的预测:

    > 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
    

    【讨论】:

    • 感谢您的回答!在数据集上方运行 R 代码时,Error in as.matrix(y) : object 'usconsumption' not found。你从哪里得到这个数据集?我无法重建您的示例代码;(
    • usconsumptiondata.frame 还是 time-series object
    • 按照您引用的书中的说明加载fpp 包。
    • 教授您好,如果我想提取上述结果中的消费点预测值,例如 2011Q1、2011Q2 的值...?如何在训练和测试集中应用 var 预测,然后计算预测误差,如观察到的(来自测试集) - 预测值?感谢您的回答?
    • 这里不是问新问题的地方。
    猜你喜欢
    • 2021-10-26
    • 2015-08-22
    • 1970-01-01
    • 2021-03-26
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多