post_gamma_state_variance | R Documentation |
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.
post_gamma_state_variance(a, a_init, shape_prior, rate_prior, inverse)
a |
a |
a_init |
a |
shape_prior |
a |
rate_prior |
a |
inverse |
logical. If |
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 \Simga_v
.
A matrix.
Chan, J., Koop, G., Poirier, D. J., & Tobias J. L. (2019). Bayesian econometric methods (2nd ed.). Cambridge: Cambridge University Press.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.