[R] Simulation of VAR

Ron_M ron_michael70 at yahoo.com
Mon Mar 29 11:29:23 CEST 2010


Yes I looked into "dse" package. Here I have implemented two approach for
simulation like following :

library(dse)
A1 <- matrix(rnorm(16),4)
A2 <- matrix(rnorm(16),4)
mu <- rnorm(4)
sigma <- matrix(c(0.006594712,
0.006467731,
-0.000254914,
0.005939934,
0.006467731,
0.006654184,
-0.000384097,
0.005658247,
-0.000254914,
-0.000384097,
0.000310294,
4.34141E-05,
0.005939934,
0.005658247,
4.34141E-05,
0.00574024), 4)
initial.val <- matrix(c(-0.2347096,
-0.1803612,
-0.2780356,
-0.2154427 ,
3.740364,
3.757908,
3.50216 ,
3.57783), 2)

##### My approach
res <- matrix(NA, 4,4); res[c(1,2),] <- initial.val
library(mnormt); shocks <- rmnorm(2, rep(0,4), sigma)
for (i in 1:2) {
      res[i+2,] <- mu + A1%*%res[i+2-1,] + A2%*%res[i+2-2,] + shocks[i,] }
res
##### dse approach
temp1 <- matrix(t(cbind(diag(4), A1, A2)), ncol = 4, byrow = TRUE)
model <- ARMA(A=array(temp1, c(3,4,4)), B=diag(4), TREND=mu)
simulate(model, y0=initial.val, sampleT=2, noise=shocks)


Ideally last two rows of "res" and simulate() should be exactly same.
However that is not what I am getting. Can anyone please tell me whether
there is any mistale in any of those approaches? Am I missing somthing?

Thanks
-- 
View this message in context: http://n4.nabble.com/Simulation-of-VAR-tp1693295p1694899.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list