helpers {bvarsv}R Documentation

Helper Functions to Access BVAR Forecast Distributions and Parameter Draws


Functions to extract a univariate posterior predictive distribution from a model fit generated by


predictive.density(fit, v = 1, h = 1, cdf = FALSE)
predictive.draws(fit, v = 1, h = 1)
parameter.draws(fit, type = "lag1", row = 1, col = 1)



List, model fit generated by


Index for variable of interest. Must be in line with the specification of fit.


Index for forecast horizon of interest. Must be in line with the specification of fit.


Set to TRUE to return cumulative distribution function, set to FALSE to return probability density function


Character string, used to specify output for function parameter.draws. Setting to "intercept" returns parameter draws for the intercept vector. Setting to one of "lag1", ..., "lagX", (where X is the lag order used in fit) returns parameter draws from the autoregressive coefficient matrices. Setting to "vcv" returns draws for the elements of the residual variance-covariance matrix.

row, col

Row and column index for the parameter for which parameter.draws should return posterior draws. That is, the function returns the row, col element of the matrix specified by type. Note that col is irrelevant if type = "intercept" has been chosen.


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 list containing vectors of MCMC draws, more specifically:


Draws from the predictand itself


Mean of the normal distribution for the predictand in each draw


Variance of the normal distribution for the predictand in each draw

Both outputs should be closely in line with each other (apart from a small amount of sampling noise), see the link below for details.

parameter.draws returns posterior draws for a single (scalar) parameter of the model fitted by The output is a matrix, with rows representing MCMC draws, and columns representing time.


Fabian Krueger

See Also

For examples and background, see the accompanying pdf file hosted at


## Not run: 

# Load US macro data

# Estimate trivariate BVAR using default settings
bv <-

# 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")

## End(Not run)

[Package bvarsv version 1.1 Index]