Learn R Programming

BayesLogit (version 0.5.1)

draw.ar1.ind: AR1 Tools

Description

Generate posterior draw of parameters from a collection of independent AR(1) processes.

Usage

draw.W.ar1.ind(x, mu, phi, a.0, b.0)
  draw.phi.ar1.ind(x, mu, W, phi.m0, phi.P0, phi.prev)
  draw.mu.ar1.ind(x, phi, W, mu.m0, mu.P0)

Arguments

x
P x N+1 matrix.
mu
P dim vector
phi
P dim vector
W
A P dim vector.
a.0
A P dim vector corresponding to IGa(a.0/2, b.0/2) prior for W.
b.0
A P dim vector corresponding to IGa(a.0/2, b.0/2) prior for W.
mu.m0
A P dim vector corresponding to prior mean.
mu.P0
A P dim vector corresponding to component precisions.
phi.m0
A P dim vector corresponding to prior mean.
phi.P0
A P dim vector corresponding to component precisions.
phi.prev
Previous phi.

Value

  • Return posterior draw, in each case a one-dimensional array.

Details

These routines work for a collection of independent AR(1)'s, i.e. a VAR(1), $$x_t = \mu + \phi \odot (x_{t-1} - \mu) + \omega_t, \, \omega_t \sim N(0, W),$$ where $\mu$ and $\phi$ are arrays and $W$ is diagonal.

We assume the posterior draw for $\phi$ must lie in $(0,1)$ and thus return the previous value of $\phi$ when that is not the case.

Examples

Run this code
N   = 100
  P.b = 2
  mu  = rep(0.3, P.b)
  phi = rep(0.95, P.b)
  W   = rep(0.1, P.b)
  m0  = rep(0, P.b)
  C0  = rep(1, P.b)

  beta0  = m0 + sqrt(C0) * rnorm(P.b, 0, 1)

  beta = matrix(0, nrow=P.b, ncol=N+1)
  beta[,1] = beta0
  
  for (i in 2:(N+1)) {
    beta[,i] = mu + phi * (beta[,i-1] - mu) + sqrt(W) * rnorm(P.b, 0, 1);
  }   

  W.vec = diag(W)
  mu  = draw.mu.ar1.ind (beta, phi, W.vec, rep(0, P.b), rep(0, P.b))
  phi = draw.phi.ar1.ind(beta, mu , W.vec, rep(0.9, P.b), rep(0, P.b), 0.5)
  W   = draw.W.ar1.ind  (beta, mu, phi, rep(2, P.b), rep(2, P.b))

Run the code above in your browser using DataLab