A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bsvars/bsvars/issues/69 below:

compute_variance_decompositions R vs cpp · Issue #69 · bsvars/bsvars · GitHub

Hey @donotdespair

compute_variance_decompositions gives a different result from the R function compute_fevd

Here is a reproducible example

library(bsvarSIGNs)

# R code for fevd
compute_fevd = function(irf, horizon = 40) {
  N    = dim(irf)[1]
  S    = dim(irf)[4]
  fevd = array(NA,c(N,N,horizon,S))
  
  for (s in 1:S){
    
    for (i in 1:(horizon)){
      
      for (n in 1:N){
        for (nn in 1:N){
          fevd[n,nn,i,s]  = sum(irf[n,nn,1:i,s]^2)
        }
      }
      fevd[,,i,s]         = diag(1/apply(fevd[,,i,s],1,sum))%*%fevd[,,i,s]
    }
  }
  
  fevd        = 100*fevd
  fevd
}

data(optimism)

zero_irf          = matrix(0, nrow = 5, ncol = 5)
zero_irf[1, 1]    = 1
sign_irf          = array(0, dim = c(5, 5, 1))
sign_irf[2, 1, 1] = 1

specification = specify_bsvarSIGN$new(
  optimism*100,
  p        = 4,
  sign_irf = sign_irf,
  zero_irf = zero_irf
)

posterior = estimate(specification, S = 100)
irf       = compute_impulse_responses(posterior, horizon = 40)

fevd_R    = compute_fevd(irf, horizon = 10)
fevd_cpp  = compute_variance_decompositions(posterior, horizon = 10)

fevd_R[,,1,1]
fevd_cpp[,,1,1]

Seems like the R function is correct, have a look! Thanks.

Best,
Adam


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4