Hello Ahmad,
you can use 'ar.ols' from the package 'ts'. Save the residual
matrix, do the
orthogonalization and calculate the impulse response matrices recursively as
an array. You can then easily retrieve the impulse responses and plot them:
VAR <- ar.ols('your data', aic=F,demean=F, intercept=T, order=4)
res <- VAR$resid
res <- na.omit(res)
sig <- var(res)
A <- t(chol(sig))
I <- diag(3)
A <- lower.tri(A)*A+I
# performing Choleski decomp above and setting main diagnols to 1, i.e. unit
shocks
#
ID <- diag(K)
NM <- matrix(0,nrow=K,ncol=K*pvar)
B <- array(NA, c(K,K,ira))
# defining identity and null matrix for ira to calculate in for loop (K:
number of variables in var, ira: number of periods for ira, pvar: number of
lags in var
#
tmp <- cbind(ID,NM)[1:K,1:(K*pvar)]
for(i in 1:ira)
{
tmpB <- tmp%*%Dstack
tmp <- cbind(tmpB,tmp)[1:K,1:(K*pvar)]
B[,,i] <- tmpB%*%A
}
# Generating and saving the bar plots
#
for(i in 1:K)
{
for(j in 1:K)
{
jpeg(filename=paste("ira_y",i,"_on_y",j,".jpg",sep=""))
barplot(B[j,i,],col="seagreen",names.arg=c(1:ira),main="Orthogonal
Impulse
Response",sub=paste("Unit shock in y",i," on y",j,
sep="" ))
dev.off()
}
}
See also my Email sent out yesterday concerning VECM and ira (subject:
Function: VECM (Johansen).
Rgds,
Bernhard
-----Original Message-----
From: hammour [mailto:hammour at msn.com]
Sent: 09 September 2002 20:31
To: R-help at stat.math.ethz.ch
Subject: [R] impulse response function
Hi,
Is there a function in any of R-packages that can produce and plot the
impulse response function for any model..
Thank you
Ahmad Abu Hammour
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
If you have received this e-mail in error or wish to read our e-mail disclaimer
statement and monitoring policy, please refer to http://www.drkw.com/disc/email/
or contact the sender
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._