Closed christophsax closed 5 years ago
Pushed a sanity check to master. When I run the following in a fresh R session, it fails, like below. But it works fine in a reprex. So this returns sometimes NaN
, sometimes not. Don't get it.
> library(bdfm)
> logs <- c("W068RCQ027SBEA", "PCEDG", "PCEND", "JTSJOL", "INDPRO", "CSUSHPINSA", "HSN1F", "TSIFRGHT", "IPG2211S", "DGORDER", "AMTMNO", "CPILFESL", "ICSA")
> diffs <- setdiff(colnames(econ_us), c("A191RL1Q225SBEA", "USSLIND"))
>
> m <- dfm(data = econ_us, factors = 3, pre_differenced = "A191RL1Q225SBEA", store_idx = "A191RL1Q225SBEA",
+ logs = logs, diffs = diffs)
Error in bdfm(Y = Y, m = m, p = p, Bp = Bp, lam_B = lam_B, Hp = Hp, lam_H = lam_H, :
!all(is.na(Est$Ys)) is not TRUE
This looks like the standard us_gdp.R example, right? Odd that it errors... Every time I've run it it's been fine. However, based on what you've said I have a pretty good idea what's going on:
NaN's typically come from the Rcpp code (C++ doesn't support NA; NaN is the numeric (double) alternative to an actual value). This happens when simulated draws for parameters and factors are not stationary --- one or the other explodes and results in NaN values. The reason you might get it some times and not others is because we're drawing for factors and parameters, and it could be the case that sometimes these draws converge to nice stationary distributions and sometimes they don't. For a truly reproducible example we need to set the RNG seed in the C++ code. This is something we'll have to introduce at some point... I looked into it and it wasn't obvious to me how to go about it since we're doing so many simulations in different places in the code.
However, I still think it's odd than any run of the us_gdp.R example would not have converged... I've run it probably 50 times and never had a problem. Is there anything particularly different about this example or the environment?
Quick update here --- I moved the error message into the C++ code so it will break earlier of draws are not stationary, and it returns the error "Draws non-stationary" which is hopefully more informative.
However, I still think it's odd than any run of the us_gdp.R example would not have converged... I've run it probably 50 times and never had a problem. Is there anything particularly different about this example or the environment?
When I opened the issue, I got the problem every time, so it was probably something on top of the seed. Since it is gone now, and we cannot reproduce, I guess we close this. Setting the seed in cpp would be valuable if we run into similar situations.
I got some weird results auf of
bdfm
but cannot build a reprex for some reason. If you look at the inputs below, can you tell me whybdfm
retuns the following:Input