Learn R Programming

bvartools (version 0.3.0)

post_gamma_state_variance: Posterior Draws of Error Variances

Description

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

Usage

post_gamma_state_variance(a, a_init, shape_prior, rate_prior, inverse)

Value

A matrix.

Arguments

a

a \(KT \times 1\) vector of time varying parameter draws.

a_init

a \(K \times 1\) vector of initial states.

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 the state space model with state equation $$a_t = a_{t-1} + v$$ and measurement equation $$y_t = Z_{t} a_t + u_t$$ with \(v_t \sim N(0, \Sigma_{v})\) and \(u_t \sim N(0, \Sigma_{u,t})\) the function produces a draw of the constant diagonal error variances matrix of the state equation \(\Sigma_v\).

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 artificial coefficients
tt <- 1000 # Number of observations

set.seed(1234) # Set RNG seed

# Generate artificial data according to a random walk
a <- matrix(rnorm(k), k, tt + 1)
for (i in 2:(tt + 1)) {
  a[, i] <- a[, i - 1] + rnorm(k, 0, sqrt(1 / 100))
}

a_init <- matrix(a[, 1]) # Define initial state
a <- matrix(a[, -1]) # Drop initial state from main sample and make vector

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

# Obtain posterior draw
post_gamma_state_variance(a, a_init, shape_prior, rate_prior, inverse = FALSE)

Run the code above in your browser using DataLab