Introduction to vwIRF

The general idea behind this code has been borrowed from the original work by Hsiang (2012) and its adaptation to R by Schönbrodt (2012). I adapt here some paragraphs of Sol’s blog on visually weighted regressions to motivate the use of visually weighted plots in order to efficiently convey uncertainty.

Uncertainty in statistical analysis can be efficiently and effectively communicated using the visual properties of lines. Altering the “visual weight” of lines to depict the quality of information represented clearly communicates statistical confidence even when readers are unfamiliar or reckless with the formal and abstract definitions of statistical uncertainty. Here, we present an example by decreasing the color-saturation of time paths lines. The result is a simple, visually intuitive and graphically compact display of statistical uncertainty.

At a simple glance, the researcher or policy maker can have a clear and intuitive picture of the uncertainty associated to a determined estimation or simulation. In the event that she has to make a decision based on data, she will have a strong understanding of the possible outcomes that might result from her decision. Needless to say, the reliability of this method rests on a precise, quantitative estimate of uncertainty. An example of visually weighted techniques applied to regression analysis is depicted in the following figure.

Caption

The goal of visually-weighted displaying techniques is to take advantage of viewer’s psychological response to images in order to focus their attention on the results that are the most informative. The general innovation here is to utilise the visual properties of lines to communicate statistical uncertainty intuitively.

Browsing the code

Here, I describe the internal functioning and options of the R function vwIRF.R, which will yield visually weighted time paths taking multiple individual time paths as input (I suggest to use N>100 lines as input). I decided to name this function vwIRF.R because I foresee its direct application to the uncertainty analysis of Impulse Response Functions, very popular in macroeconomic simulations derived from DSGE models.

Following Schönbrodt, I implemented the code in R using ggplot2. To make this code work, you will also need the followwing R libraries: reshape2. plyr. RColorBrewer and extrafont.

Variables in your database must be arranged in columns; rows are reserved for time steps.

The code calculates density estimates for each vertical cut (y-slice) of your input lines. The area under the density curve always is 1, so the ink is constant for each y-slice. The figure is shaded according to these density estimates.

Nice and simple. After sourcing the function in your main file (in case that this is not located in the same working directory as your main file), typing

p<-vwIRF(data)

would yield

Since this function is built upon the ggplot2 library, the resulting output can be modified adding additional layers to our graphical object. For instance,

p <- p + ylim(1000,3000)