helpers {bvarsv}R Documentation

Helper Functions to Access BVAR Forecast Distributions and Parameter Draws

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)
parameter.draws(fit, type = "lag1", row = 1, col = 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

type

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.

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

y

Draws from the predictand itself

m

Mean of the normal distribution for the predictand in each draw

v

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 bvar.sv.tvp. The output is a matrix, with rows representing MCMC draws, and columns representing time.

Author(s)

Fabian Krueger

See Also

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

Examples

## Not run: 

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


## End(Not run)

[Package bvarsv version 1.1 Index]