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)
Run the code above in your browser using DataLab