Learn R Programming

bvarsv (version 1.0)

helpers: Helper Functions to Access BVAR Forecast Distributions

Description

Functions to extract a univariate posterior predictive distribution from a model fit generated by bvar.sv.tvp.

Usage

predictive.density(fit, v = 1, h = 1, cdf = FALSE)
predictive.draws(fit, v = 1, h = 1)

Arguments

fit
List, model fit generated by bvar.sv.tvp
v
Index for variable of interest. Must be in line with the specification of fit.
h
Index for forecast horizon of interest. Must be in line with the specification of fit.
cdf
Set to TRUE to return cumulative distribution function, set to FALSE to return probability density function

Value

  • predictive.density returns a function f(z), which yields the value(s) of the predictive density at point(s) z. This function exploits conditional normality of the model, given the posterior draws of the parameters. predictive.draws returns a vector of MCMC draws. Both outputs should be closely in line with each other (apart from a small amount of sampling noise), see the link below for details.

See Also

For examples and background, see the accompanying pdf file hosted at https://sites.google.com/site/fk83research/code.

Examples

Run this code
# Load US macro data
data(usmacro)

# Estimate trivariate BVAR using default settings
set.seed(5813)
bv <- bvar.sv.tvp(usmacro)

# Construct predictive density function for the second variable (inflation), one period ahead
f <- predictive.density(bv, v = 2, h = 1)

# Plot the density for a grid of values
grid <- seq(-2, 5, by = 0.05)
plot(x = grid, y = f(grid), type = "l")

# Cross-check: Extract MCMC sample for the same variable and horizon
smp <- predictive.draws(bv, v = 2, h = 1)

# Add density estimate to plot
lines(density(smp), col = "green")

Run the code above in your browser using DataLab