helpers {bvarsv} | R Documentation |
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)
fit |
List, model fit generated by |
v |
Index for variable of interest. Must be in line with the specification of |
h |
Index for forecast horizon of interest. Must be in line with the specification of |
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 |
row, col |
Row and column index for the parameter for which |
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.
Fabian Krueger
For examples and background, see the accompanying pdf file hosted at https://sites.google.com/site/fk83research/code.
## 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)