Learn R Programming

bvartools (version 0.3.0)

post_gamma_measurement_variance: Posterior Draws of Error Variances

Description

Produces a draw of the constant diagonal error variance matrix of the measurement equation of a state space model using an inverse gamma posterior density.

Usage

post_gamma_measurement_variance(u, shape_prior, rate_prior, inverse)

Value

A matrix.

Arguments

u

a \(KT \times 1\) vector of errors.

shape_prior

a \(K \times 1\) vector of prior shape parameters.

rate_prior

a \(K \times 1\) vector of prior rate parameters.

inverse

logical. If TRUE, the function returns the precision matrix, i.e. the inverse of the variance matrix. Defaults to FALSE.

Details

For a model with measurement equation $$y_t = Z_{t} a_t + u_t$$ with \(u_t \sim N(0, \Sigma_{u})\) the function produces a draw of the constant diagonal error variance matrix \(\Sigma_u\).

References

Chan, J., Koop, G., Poirier, D. J., & Tobias J. L. (2019). Bayesian econometric methods (2nd ed.). Cambridge: Cambridge University Press.

Examples

Run this code

k <- 10 # Number of endogenous variables
tt <- 1000 # Number of observations

set.seed(1234) # Set RNG seed

# Generate artificial error series with N(0, 1)
u <- matrix(rnorm(k * tt))

# Define priors
shape_prior <- matrix(1, k)
rate_prior <- matrix(.0001, k)

# Obtain posterior draw
post_gamma_measurement_variance(u, shape_prior, rate_prior, inverse = FALSE)

Run the code above in your browser using DataLab