Reputation: 5345
On the following site(https://www.otexts.org/fpp/9/2) a Vector autoregressions is created.
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)
The code is rather simple, but when creating the forecast:
fcst <- forecast(var)
plot(fcst, xlab="Year")
The forecast
function does not work. However, using the predict
function does not yield the same plot as the forecast function.
Any suggestions, how to obtain the plot from the provided link?
I appreciate your replies!
Upvotes: 1
Views: 3271
Reputation: 31800
What do you mean "the forecast
function does not work"? I get exactly the plot you want and the predict function gives exactly the same forecasts:
> 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
Upvotes: 3