Helper Functions to Access BVAR Forecast Distributions and Parameter Draws
Helper Functions to Access BVAR Forecast Distributions and Parameter Draws
Functions to extract a univariate posterior predictive distribution from a model fit generated by bvar.sv.tvp.
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.
Returns
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
Examples
## Not run:# Load US macro datadata(usmacro)# Estimate trivariate BVAR using default settingsset.seed(5813)bv <- bvar.sv.tvp(usmacro)# Construct predictive density function for the second variable (inflation), one period aheadf <- predictive.density(bv, v =2, h =1)# Plot the density for a grid of valuesgrid <- seq(-2,5, by =0.05)plot(x = grid, y = f(grid), type ="l")# Cross-check: Extract MCMC sample for the same variable and horizonsmp <- predictive.draws(bv, v =2, h =1)# Add density estimate to plotlines(density(smp), col ="green")## End(Not run)