# How to draw IRFs and confidence bands in R

How can I plot Impulse Responses Functions and confidence bands in R as shown in the image below:

• See the vars package. – Christoph Hanck Sep 11 '15 at 14:56
• Thanks @Christoph, but I want to have some sort of shading between the confidence bands as in this image. – mr.rox Sep 11 '15 at 14:59
• If you retrieve the upper and lower values of the bands, you can do that with the general purpose polygon command. – Christoph Hanck Sep 11 '15 at 15:01

## 1 Answer

Here is an answer using the polygon function in R

#Generate some psuedo data
x = seq(0,10,.01)
IRF = sin(pi*x/5)+.8*cos(4*pi*x/5)  #This is the IRF values
lower = IRF - 1                     #Lower 95% limit
upper = IRF + 1                     #Upper 95% limit

plot(x,IRF,type="n",ylim=c(-3,3))
polygon(c(x,rev(x)),c(lower,rev(upper)),col="lightgrey",border=NA)  #This function creates the CI bands
lines(x,IRF,col="darkblue")
box()


This code generates the following image: • My code makes the assumptions that you can calculate or have the values for IRF and the upper and lower limits of the confidence interval. – user30490 Sep 11 '15 at 15:03