Learn R Programming

BayesLogit (version 0.5.1)

ar1.llh: AR1 Tools

Description

Calculate log-likelihood of a VAR(1).

Usage

ar1.llh.C(beta, mu, phi, W, m0, C0, alpha=NULL)

Arguments

beta
A P.b x (N+1) matrix.
alpha
A P.a dim vector.
mu
A P.b dim vector.
phi
A P.b dim vector.
W
A P.b x P.b matrix.
m0
A P dim vector
C0
A P x P dim matrix.

Value

  • Return the log-density, up to a shift by a function of C0.

Details

Calculate log-density for a VAR(1) of the form

$$\beta_t = \mu + \phi \odot (\beta_{t-1} - \mu) + \omega_t, \, \omega_t \sim N(0, W),$$

where $\mu$ and $\phi$ are arrays and $W$ is a matrix and $$(\alpha, \beta_0) \sim N(m0, C0).$$

Examples

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

  ab  = m0 + t(chol(C0)) %*% rnorm(P, 0, 1)
  alpha = ab[1:P.a]
  beta0 = ab[(P.a+1):P.b]

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

  llh = ar1.llh.C(beta, mu, phi, W, m0, C0, alpha=alpha)
  llh

Run the code above in your browser using DataLab