简体   繁体   中英

Plot side-by-side Impulse Response in R package “vars”

library(vars)
data(Canada)
var_fit <- VAR(Canada, p = 1)
var_irf <- irf(var_fit, impulse = c("U", "rw"), response = "prod")

How do I plot the two Impulse Responses in a figure side-by-side

Normally, I'd use par(mfrow = c(1,2)) , but it doesn't work as expected. Any help?

I found the same problem. I solved "manually", here a example for a model VAR(1) with two variables.

    impulse<-irf(model)
    irf1<-data.frame(impulse$irf$y1[,1],impulse$Lower$y1[,1],
                     impulse$Upper$y1[,1])
    irf2<-data.frame(impulse$irf$y1[,2],impulse$Lower$y1[,2],
                     impulse$Upper$y1[,2])
    par(mfrow=c(1,2), bg="azure2")
    matplot(irf1, type="l", lwd=2, col="blue2", 
            ylab=expression(y[1]), lty=c(1,2,2))
    matplot(irf2, type="l", lwd=2, col="red2", 
            ylab=expression(y[1]), lty=c(1,2,2))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM