Fitted VAR model of the class VAR, BVAR, BSVAR, or MSBVAR
produced by reduced.form.var, szbvar,
szbsvar or gibbs.msbvar.
nsteps
Number of periods in the forecast horizon
A0
m x m matrix of the decomposition of the
contemporaneous endogenous forecast innovations for BSVAR models.
shocks
Structural shocks to the VAR, BVAR, or BSVAR models.
These must be scaled consistent with the structural identification
in A(0).
exog.fut
nsteps x number of exogenous variables matrix of the
future values of exogenous variable shocks. Only implemented for
VAR, BVAR, and BSVAR models at present.
N1
integer, number of burnin draws for the MSBVAR forecasts.
N2
integer, number of final posterior draws for MSBVAR
forecasts.
Details
VAR / BVAR / BSVAR models:
This function computes forecasts for the classical and Bayesian
VAR models that are estimated in the MSBVAR package. Users can
specify shocks to the system over the forecast horizon (both
structural and exogenous shocks) for VAR, BVAR, and
BSVAR models. The forecasting model is that described by Waggoner and
Zha (1999) and can be used to construct unconditional forecasts based
on the structural shocks and the contemporaneous decomposition of the
innovation variance, A0.
MSBVAR:
Generates a set of N2 draws from the posterior forecast
density. Forecasts are constructed using data augmentation, so the
forecasts account for both forecast and parameter uncertainty. The
function for the MSBVAR model takes as arguments varobj, which
is the posterior parameters from a call to gibbs.msbvar,
and N1 and N2 to set the burnin and number of draws from
the posterior. The posterior forecasts are based on the mixture over
the h regimes for the specified model.
Value
For VAR, BVAR, and BSVAR models:
A matrix time series object,
(T + nsteps) x m of the original
series and forecasts.
For MSBVAR models, a list of 4 elements:
forecasts
N2 x nsteps x m
array of the posterior forecasts.
ss.sample
bit compressed version of the MS state space. (can
be summarized with plot.SS or mean.SS.)
k
number of forecast steps, nsteps
h
integer, number of MS regimes used in the forecasts.
Note
The forecasts can be plotted using the plot.forecast()
command to select the appropriate sample-forecast horizon.
Author(s)
Patrick T. Brandt
References
Waggoner, Daniel F. and Tao Zha. 1999. "Conditional
Forecasts in Dynamic Multivariate Models" Review of Economics and
Statistics, 81(4):639-651.
See Also
reduced.form.var, szbvar and
szbsvar for estimation methods that create the elements
needed to forecast
Examples
data(IsraelPalestineConflict)
Y.sample1 <- window(IsraelPalestineConflict, end=c(2002, 52))
Y.sample2 <- window(IsraelPalestineConflict, start=c(2003,1))
# Fit a BVAR model
fit.bvar <- szbvar(Y.sample1, p=6, lambda0=0.6, lambda1=0.1, lambda3=2,
lambda4=0.25, lambda5=0, mu5=0, mu6=0, prior=0)
# Forecast -- this gives back the sample PLUS the forecasts!
forecasts <- forecast(fit.bvar, nsteps=nrow(Y.sample2))
forecasts.only <- forecasts[(nrow(Y.sample1)+1):nrow(forecasts),]
# Plot forecasts and actual data
i2p <- ts(cbind(Y.sample2[,1], forecasts.only[,1]),
start=c(2003,1), freq=52)
p2i <- ts(cbind(Y.sample2[,2], forecasts.only[,2]),
start=c(2003,1), freq=52)
par(mfrow=c(2,1))
plot(i2p, plot.type=c("single"))
plot(p2i, plot.type=c("single"))
## Not run:
# MSBVAR forecasts
# Fit model
m1 <- msbvar(Y.sample1, p=1, h=2, lambda0=0.8, lambda1=0.2,
lambda3=1, lambda4=0.2, lambda5=0, mu5=0, mu6=0,
qm=12, prior=0)
# Gibbs sampling
m1id <- gibbs.msbvar(m1, N1=1000, N2=10000, permute=FALSE, Sigma.idx=1)
# Forecast density estimation
msforc <- forecast(m1id, nsteps=nrow(Y.sample2), N1=1000, N2=10000)
# Summarize forecasts
apply(msforc$forecasts, c(2,3), mean)
## End(Not run)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(MSBVAR)
##
## MSBVAR Package v.0.9-2
## Build date: Mon Jul 4 19:53:10 2016
## Copyright (C) 2005-2016, Patrick T. Brandt
## Written by Patrick T. Brandt
##
## Support provided by the U.S. National Science Foundation
## (Grants SES-0351179, SES-0351205, SES-0540816, and SES-0921051)
##
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/MSBVAR/forecast.Rd_%03d_medium.png", width=480, height=480)
> ### Name: forecast
> ### Title: Generate forecasts for fitted VAR objects
> ### Aliases: forecast
> ### Keywords: ts regression
>
> ### ** Examples
>
> data(IsraelPalestineConflict)
> Y.sample1 <- window(IsraelPalestineConflict, end=c(2002, 52))
> Y.sample2 <- window(IsraelPalestineConflict, start=c(2003,1))
>
> # Fit a BVAR model
> fit.bvar <- szbvar(Y.sample1, p=6, lambda0=0.6, lambda1=0.1, lambda3=2,
+ lambda4=0.25, lambda5=0, mu5=0, mu6=0, prior=0)
>
> # Forecast -- this gives back the sample PLUS the forecasts!
>
> forecasts <- forecast(fit.bvar, nsteps=nrow(Y.sample2))
> forecasts.only <- forecasts[(nrow(Y.sample1)+1):nrow(forecasts),]
>
> # Plot forecasts and actual data
> i2p <- ts(cbind(Y.sample2[,1], forecasts.only[,1]),
+ start=c(2003,1), freq=52)
>
> p2i <- ts(cbind(Y.sample2[,2], forecasts.only[,2]),
+ start=c(2003,1), freq=52)
>
> par(mfrow=c(2,1))
> plot(i2p, plot.type=c("single"))
> plot(p2i, plot.type=c("single"))
>
>
> ## Not run:
> ##D # MSBVAR forecasts
> ##D
> ##D # Fit model
> ##D m1 <- msbvar(Y.sample1, p=1, h=2, lambda0=0.8, lambda1=0.2,
> ##D lambda3=1, lambda4=0.2, lambda5=0, mu5=0, mu6=0,
> ##D qm=12, prior=0)
> ##D
> ##D # Gibbs sampling
> ##D m1id <- gibbs.msbvar(m1, N1=1000, N2=10000, permute=FALSE, Sigma.idx=1)
> ##D
> ##D # Forecast density estimation
> ##D msforc <- forecast(m1id, nsteps=nrow(Y.sample2), N1=1000, N2=10000)
> ##D
> ##D # Summarize forecasts
> ##D apply(msforc$forecasts, c(2,3), mean)
> ##D
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>