Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems running main.R #11

Open
matdehaven opened this issue Feb 7, 2025 · 11 comments
Open

Problems running main.R #11

matdehaven opened this issue Feb 7, 2025 · 11 comments
Assignees

Comments

@matdehaven
Copy link
Collaborator

"horserace_ecy" robustness

Gives the following error:

Error in lhout[idraw] <- gout$lhout : replacement has length zero

This is coming from "1_vol_bvar_estimation.R" script, in the gdraw() function on line 78.

"horserace_nfci" robustness

Gives the following error:

Error in MASS::mvrnorm(n = 1, mu = rep(0, length(optout$x)), Sigma = optout$opt$H) : 
  'Sigma' is not positive definite

This is coming from "1_vol_bvar_estimation.R" script on line 45.

"1M" robustness

runs out of memory on my computer (16 GB)

@fernando-duarte
Copy link
Collaborator

Here are my results.

"horserace_ecy" robustness

Runs to completion without error in my computer.

"horserace_nfci" robustness

Runs to completion without error in my computer.

"1M" robustness

Runs to completion without error in my computer. I have 32GB.

"horserace_no_vfci_yes_gz" robustness

Gives the same error that Matt is getting in "horserace_ecy":

Error in lhout[idraw] <- gout$lhout : replacement has length zero

I ran it 10 times, and each time it gave the same error, so it does not seem to be run-dependent.

"horserace_no_vfci_yes_gz" robustness

Gives the same error that Matt is getting in "horserace_nfci" robustness:

Error in MASS::mvrnorm(n = 1, mu = rep(0, length(optout$x)), Sigma = optout$opt$H) : 
  'Sigma' is not positive definite

I also ran this one 10 times, and each time it gave the same error, so it does not seem to be run-dependent either.

@matdehaven
Copy link
Collaborator Author

It seems if I adjust the seed in 1_vol_bvar_estimation.R I am able to get those robustness checks to run. I will confirm that this is true and see if there is a seed that works for me.

I think that the Bayesian VAR is approximating a matrix inverse operation numerically, which relies upon the seed. But it must be that the matrix is close to not positive definite/invertible, so we sometimes get these errors. It is odd that it depends not just on the seed, but also which computer we are running it on.

@matdehaven
Copy link
Collaborator Author

If I change the below line

To a seed of 83622 (randomly generate seed) all of the robustness checks work for me.

@fernando-duarte
Copy link
Collaborator

I tried setting the seed set.seed(8632) got the same error as before when running horserace_nfci:

Error in MASS::mvrnorm(n = 1, mu = rep(0, length(optout$x)), Sigma = optout$opt$H) : 
  'Sigma' is not positive definite

@fernando-duarte
Copy link
Collaborator

I tried setting the seed set.seed(968) got the same error as before

@matdehaven matdehaven self-assigned this Feb 28, 2025
@matdehaven
Copy link
Collaborator Author

matdehaven commented Feb 28, 2025

  • Try editing the tightness of the bayesian priors at the following line:

mn_tight_calib <- 3
mn_decay_calib <- 0.5
if (type == "horserace_gz" | type == "horserace_tedr" | type =="horserace_ecy" | type == "horserace_gsfci" | type == "horserace_nfci" | type == "horserace_no_vfci_yes_gz" | type == "horserace_gz_tedr" | type == "horserace_no_vfci_yes_tedr"| type == "horserace_no_vfci_yes_gz_tedr") {
mn_tight_calib <- 0.5 # with second financial variable
}

@fernando-duarte
Copy link
Collaborator

Setting:

mn_tight_calib <- 3

made the entire code run without errors. On the other hand, some of the plots came out funky, e.g.:

mcmc_out_horserace_no_vfci_yes_tedr_irplot_all_shocks_TEDR_shock.pdf

mcmc_out_horserace_ecy_irplot_all_shocks_VFCI_shock.pdf

I also tried a value for mn_tight_calib of 1, but that gave the same error as when I set it to the original value of 0.5.

Any suggestions on what value to pick?

@matdehaven
Copy link
Collaborator Author

I was only able to get the code to run when I increased the mn_tight_calib to 100. I got the same errors as before trying 3, 5, and 10.

For those figures, however, I think the problem is just that the y-axis scale is hard-coded here:

} else if (type == "horserace_tedr") {
vars_in_system <- c('lgdp', 'lpce', 'vfci', 'tedr', 'fedfunds')
var_names <- c("Log Real GDP", "Log Core PCE", "VFCI", "TEDR", "Fed Funds")
shock_names <- c("Real GDP shock", "Core PCE shock", "VFCI shock", "TEDR shock", "Fed Funds shock")
yaxis_vfci_shock <- list(c(-0.015,0.002),c(-0.005,0.005),c(-0.04,0.3),c(-0.04,0.4),c(-0.005,0.001))
yaxis_vfci_response <- list(c(-0.1,0.1),c(-0.05,0.05),c(-0.04,0.3),c(-0.04,0.1),c(-0.015,0.15))

@matdehaven
Copy link
Collaborator Author

matdehaven commented Mar 7, 2025

I think I found the solution.

I have added the following code:

disperse = TRUE ## if TRUE, disperse the starting point using inverse hessian as covariance matrix
## For some of the robustness checks, the inverse hessian matrix doesn't work, so we set disperse to FALSE
if (type == "horserace_gz" | type == "horserace_tedr" | type =="horserace_ecy" | type == "horserace_gsfci" | type == "horserace_nfci" | type == "horserace_no_vfci_yes_gz" | type == "horserace_gz_tedr" | type == "horserace_no_vfci_yes_tedr"| type == "horserace_no_vfci_yes_gz_tedr") {
disperse <- FALSE
}

The "disperse" option uses the inverse hessian to adjust the start of the bayesian draws. This inverse hessian matrix is the one that doesn't work for some of us, on some seeds, for some of the horserace robustnesses. If I turn it off, then the code runs for me. I have set the mn_tight_calib value to 3 for all robustness runs, which is what we have been using for the baseline.

@fernando-duarte @ti719 Can someone confirm the code runs for them in this new state?

@matdehaven
Copy link
Collaborator Author

Also, I have updated the y-axes for the IRF figures to try to fix the problem Fernando was noting earlier. There might still be a few that need tweaking.

@ti719
Copy link
Contributor

ti719 commented Mar 9, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants