23 thoughts on “Bank of England Fan Charts in R”

  1. Great stuff, thanks a lot for sharing!

    I was able to reproduce the graphs without too many problems. Comments:

    1. the plus sign in front of xx[,t], presumably added automatically by the R or html editor, should be removed, as far as I could tell.

    2. to match exactly the incomplete data for 2013 should be dropped, e.g. add this line: cpi <- na.omit(cpi).

    3. Here's the data I used to replicate:

    cpi
    Qtr1 Qtr2 Qtr3 Qtr4
    1997 1.9 1.6 2.0 1.9
    1998 1.6 2.0 1.3 1.4
    1999 1.4 1.3 1.2 1.2
    2000 0.9 0.5 0.6 1.1
    2001 0.8 1.7 1.8 0.8
    2002 1.5 0.8 1.0 1.5
    2003 1.6 1.3 1.4 1.3
    2004 1.3 1.5 1.3 1.5
    2005 1.7 1.9 2.4 2.1
    2006 2.0 2.2 2.5 2.7
    2007 2.8 2.5 1.8 2.1
    2008 2.5 3.3 4.7 4.1
    2009 3.2 2.2 1.6 1.9
    2010 3.0 3.4 3.1 3.3
    2011 4.4 4.5 4.5 4.8
    2012 3.4 2.8 2.5 2.7

    cpiboe
    Year Quarter Mode Median Mean Uncertainty Skewness
    1 2013 Q1 2.73 2.73 2.73 0.61 0
    2 2013 Q2 2.92 2.92 2.92 0.88 0
    3 2013 Q3 3.22 3.22 3.22 1.11 0
    4 2013 Q4 3.13 3.13 3.13 1.27 0
    5 2014 Q1 2.95 2.95 2.95 1.34 0
    6 2014 Q2 2.82 2.82 2.82 1.37 0
    7 2014 Q3 2.53 2.53 2.53 1.39 0
    8 2014 Q4 2.41 2.41 2.41 1.42 0
    9 2015 Q1 2.32 2.32 2.32 1.48 0
    10 2015 Q2 2.23 2.23 2.23 1.49 0
    11 2015 Q3 2.13 2.13 2.13 1.50 0
    12 2015 Q4 2.01 2.01 2.01 1.52 0
    13 2016 Q1 1.96 1.96 1.96 1.52 0

    1. Thanks Patrick. You are correct (on all your points). I have updated the post to show all the data, hopefully making it easier to reproduce.

      1. Thanks Guy, fantastic tool you have made available here. There are so many applications!

        It would be an interesting exercise to take a look at old B of E fan charts and overlay the actual data on top of their prediction fans, and see whether the frequency is consistent with the split normal assumption used.

  2. Thanks for sharing this post. I have been trying to replicate the graph, but as soon as i run the follwing command statement along with the qsplitnorm i get the an error:
    > for (i in 1:k) {
    + xx[, i] 1 & skew < 1) stop("skew must be between -1 and 1") :
    argument is of length zero

    . I am not sure what am i missing. Would you be able to let me know if there is something very obvious that i am missing.

    1. Hi Atmajit. Not to sure what it could be from the code you give. Perhaps it could be in the format of the Bank of England data or the column names in the cpiboe data.frame?

      I just managed to replicate the example by copying the Bank of England data in the post below the lines…

      > cpiboe <- read.csv("C:/Users/…/cpiboe.csv")
      > cpiboe

      into excel. Then I used the “Text to Columns” button in excel to get the data into separate columns (see point 3 here… http://stackoverflow.com/questions/14096692/getting-r-studio-lmer-output-to-word-excel/16033373#16033373). Then I saved the file as cpiboe.csv and adjusted the path name to read the csv file into R. The code should then run fine?

    1. Its just a variable in the boe object to indicate which quarter the foretasted mean, uncertainty and skewness are from. Its not used in the fan function at all, just to obtain the subset of the boe forecast data that (in the plot above) refer to the desired launch period (2013 Q1 above).

  3. Have you tried cases in which the skewness parameter is not equal to zero? I also tried replicating the charts but only works when skewness parameter is zero. Did you derive the gamma parameter as the skewness parameter provided by the BOE does not seem to be the same as gamma?

    1. Gamma is as in the Julio (2007) paper. It is constrained to be between -1 and 1. I am able to produce fans with non-zero skew parameters with no problem. What version of the package are you using?

      1. Hello,

        My version also does not work with a non-zero skewness parameter. Have others managed to resolve this? I am using fanplot package 3.4

    2. Hello-

      For some reason cannot reply to you comment so leaving it separately.

      Data I use:
      Year Mode Skew Variance Standard Deviation
      2012 0.8 0 1.44 1.2
      2013 2 -0.5 4 2
      2014 2.7 -0.7 4.84 2.2
      2015 3 -0.7 4.84 2.2
      2016 3 -0.6 4.84 2.2

      Code:

      > year=c(2012,2013,2014,2015,2016)
      > mode= c(0.8,2,2.7,3,3)
      > skew= c(0,-0.5,-0.7,-0.7,-0.6)
      > var= c(1.44,4,4.84,4.84,4.84)
      > sd= c(1.2,2,2.2,2.2,2.2)
      > UK=data.drame(year,mode,skew,sd)
      > save(UK,file=”UK.Rda”)
      > load(“UK.Rda”)
      > edit(UK)
      year mode skew sd
      1 2012 0.8 0.0 1.2
      2 2013 2.0 -0.5 2.0
      3 2014 2.7 -0.7 2.2
      4 2015 3.0 -0.7 2.2
      5 2016 3.0 -0.6 2.2

      #works fine for this year as skew is 0
      y0 UK0 k p gdpval for(i in 1:k) gdpval[,i] gdpval

      #this does not work
      y1<-2013
      UK1<-subset(UK,year=y1)
      k<-nrow(UK1)
      p<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)
      bgdp<-matrix(NA,nrow=length(p),ncol=k)
      for(i in 1:k) bgdp[,i]<-qsplitnorm(p, mode=UK1$mode[i],sd=UK1$sd[i],
      skew=UK1$skew[i])
      bgdp

      #this also does not work (alt method dropping observations for 2012)

      year=c(2013,2014,2015,2016)
      mode= c(2,2.7,3,3)
      skew= c(-0.5,-0.7,-0.7,-0.6)
      sd= c(2,2.2,2.2,2.2)
      UK13=data.frame(year,mode,skew,sd)
      save(UK13,file="UK13.Rda")
      load("UK13.Rda")
      edit(UK13)
      y1<-2013
      UK1<-subset(UK13,year=y1)
      k<-nrow(UK1)
      p<-c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9)
      bgdp<-matrix(NA,nrow=length(p),ncol=k)
      for(i in 1:k) bgdp[,i]<-qsplitnorm(p, mode=UK1$mode[i],sd=UK1$sd[i],
      skew=UK1$skew[i])
      bgdp

      Thank you!

      1. Hi Nidhi. Do you want to post your question/code on stackoverflow, send us the link and I will answer there. I have managed to a plot your data, but I am not sure how you are using the fan function, and in any case the code won’t display very well in the wordpress comments section. Guy

  4. Hi Guy, thank you very much for this excellent tool. Just a quick question: is there an option for the fanchart to show only a number of quantiles? For example, I want it to skip the tail values and only show values between the 10%-90% quantiles.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: