alexanderlange53 / svars

R Package for data driven SVAR identification of impulse response functions
Other
44 stars 20 forks source link

Svarirf plot - cumulation #82

Closed bttomio closed 4 years ago

bttomio commented 4 years ago

Hi,

FOA, thank you very much for your package!

I am trying to accumulate the responses in the Svarirf plot. Nevertheless, using cumulative = T, results are generated only for the first variable:

a61d67fb-2353-451a-8e85-c9b11392bb4e

Here is the code:

library("svars")

ggplot2::autoplot(USA, facet = TRUE) + ggplot2::theme_bw()

reduced.form <- vars::VAR(USA, lag.max = 10, ic = "AIC" )
structural.form <- id.ngml(reduced.form)
summary(structural.form)

structural.form$B <- structural.form$B[,c(3,2,1)]
structural.form$B[,3] <- structural.form$B[,3]*(-1)
structural.form$B

impulse.response <- irf(structural.form, n.ahead = 30)
plot(impulse.response, scales = 'free_y')

cores <- parallel::detectCores() - 1
boot.svar <- wild.boot(structural.form, n.ahead = 30, nboot = 500, nc = cores)

plot(boot.svar)

plot(boot.svar, cumulative = TRUE)

Session info:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] tseries_0.10-47   BoostedHP_0.0.5   seasonal_1.7.1    BFS_0.2.5         OECD_0.2.4        IMFData_0.2.0    
 [7] anytime_0.3.9     openxlsx_4.1.5    forcats_0.5.0     stringr_1.4.0     purrr_0.3.4       readr_1.3.1      
[13] tidyr_1.1.2       tidyverse_1.3.0   tibble_3.0.3      quantmod_0.4.17   TTR_0.24.2        Quandl_2.10.0    
[19] xts_0.12-0        lubridate_1.7.9   dplyr_1.0.2       ggplot2_3.3.2     svars_1.3.3       vars_1.5-3       
[25] lmtest_0.9-37     urca_1.3-0        strucchange_1.5-2 sandwich_2.5-1    zoo_1.8-8         MASS_7.3-51.6    

loaded via a namespace (and not attached):
 [1] nlme_3.1-148        bitops_1.0-6        fs_1.5.0            progress_1.2.2      httr_1.4.2         
 [6] numDeriv_2016.8-1.1 tools_4.0.2         backports_1.1.9     R6_2.4.1            DBI_1.1.0          
[11] colorspace_1.4-1    withr_2.2.0         prettyunits_1.1.1   tidyselect_1.1.0    steadyICA_1.0      
[16] curl_4.3            compiler_4.0.2      pspline_1.0-18      cli_2.0.2           rvest_0.3.6        
[21] expm_0.999-5        xml2_1.3.2          pxR_0.42.4          labeling_0.3        scales_1.1.1       
[26] mvtnorm_1.1-1       quadprog_1.5-8      pbapply_1.4-3       digest_0.6.25       x13binary_1.1.39-2 
[31] pkgconfig_2.0.3     DEoptim_2.2-5       dbplyr_1.4.4        stabledist_0.7-1    ADGofTest_0.3      
[36] rlang_0.4.7         readxl_1.3.1        rstudioapi_0.11     farver_2.0.3        generics_0.0.2     
[41] combinat_0.0-8      jsonlite_1.7.1      zip_2.1.1           RCurl_1.98-1.2      magrittr_1.5       
[46] Matrix_1.2-18       Rcpp_1.0.5          munsell_0.5.0       fansi_0.4.1         lifecycle_0.2.0    
[51] stringi_1.4.6       snakecase_0.11.0    RJSONIO_1.3-1.4     plyr_1.8.6          grid_4.0.2         
[56] blob_1.2.1          parallel_4.0.2      crayon_1.3.4        lattice_0.20-41     haven_2.3.1        
[61] hms_0.5.3           pillar_1.4.6        reshape2_1.4.4      stats4_4.0.2        XML_3.99-0.5       
[66] reprex_0.3.0        glue_1.4.2          modelr_0.1.8        vctrs_0.3.4         cellranger_1.1.0   
[71] gtable_0.3.0        clue_0.3-57         assertthat_0.2.1    pins_0.4.3          janitor_2.0.1      
[76] broom_0.7.0         rsdmx_0.5-14        pcaPP_1.9-73        gsl_2.1-6           copula_1.0-0       
[81] cluster_2.1.0       ellipsis_0.3.1  

Many thanks,

Bruno

alexanderlange53 commented 4 years ago

Dear Bruno,

thank you for using our package.

If you want to obtain accumulated responses, you have to specify the row/variable for which you want the accumulated response, i.e. if you want to have all responses accumulated you should specify plot(boot.svar, cumulative = 1:3).

In your code above the TRUE was converted to a 1 inside the function, thats why you get cumulated irfs for the first variable.

Best regards,

Alexander

bttomio commented 4 years ago

Dear Alexander,

Thanks a lot for being so responsive.

It works flawless. Your answer also clarified to me how to use selection:

plot(boot.svar, cumulative = 1:3)

image

plot(boot.svar, cumulative = 1:3, selection = 2:1)

image

Once again, thank you for this package!

Cheers,

Bruno