Rstan swallows divergent transitions


I noticed that rstan (2.14 and 2.15) does report those numerical issues like sigma’s being 0 or so, but it does not report if a divergent transition happened. I only get these reported when looking into the get_sampler_params object.

Is this on intention?


It all comes from rstan:::throw_sampler_warnings:

funnel <- stan_demo("funnel", chains = 4)
Warning messages:
1: There were 13 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See 
2: There were 70 transitions after warmup that exceeded the maximum treedepth. Increase max_treedepth above 10. See 
3: There were 4 chains where the estimated Bayesian Fraction of Missing Information was low. See 
4: Examine the pairs() plot to diagnose sampling problems

Good, but then how can I get this output (for a single chain):

The following numerical problems occurred the indicated number of times on chain 1
Exception thrown at line 251: Exception thrown at line 117: Max number of iterations exceeded (1000)     9

And then looking into the output of the sampler params, I get:

> colSums(get_sampler_params(pk_fit_1cmt_ode_cp_par, inc_warmup=FALSE)[[1]])
accept_stat__    stepsize__   treedepth__  n_leapfrog__   divergent__ 
     73.73222      18.41194     496.00000    3083.00000       3.00000 
> colSums(get_sampler_params(pk_fit_1cmt_ode_cp_par, inc_warmup=TRUE)[[1]])
accept_stat__    stepsize__   treedepth__  n_leapfrog__   divergent__ 
    175.05365      38.34712    1383.00000   21082.00000      22.00000 

So how are things being counted? I thought whenever a divergent=1 occurs in the sampler parameters, then this is a divergence. Apparently this is not reported as such.

And as we are at it: A numerical problem like sigma’s hitting 0 or the ODE integrator failing due to reaching the maximal number of steps - how are these counted in rstan?



What happens if you call rstan:::throw_sampler_warnings() on that chain?

When I do that then I get the warning I was expecting:

> rstan:::throw_sampler_warnings(pk_fit_1cmt_ode_cp_par)
Warning messages:
1: There were 3 divergent transitions after warmup. Increasing adapt_delta above 0.7 may help. See 
2: Examine the pairs() plot to diagnose sampling problems

But this does not get displayed when the chain finishes to sample. To make sure, here is my session info:

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4

[1] de_CH.UTF-8/de_CH.UTF-8/de_CH.UTF-8/C/de_CH.UTF-8/de_CH.UTF-8

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

other attached packages:
[1] cOde_0.2.2           rstan_2.15.1         StanHeaders_2.15.0-1
[4] ggplot2_2.2.1       

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10     codetools_0.2-15 assertthat_0.1   grid_3.3.2      
 [5] plyr_1.8.4       gtable_0.2.0     stats4_3.3.2     scales_0.4.1    
 [9] lazyeval_0.2.0   tools_3.3.2      munsell_0.4.3    compiler_3.3.2  
[13] inline_0.3.14    colorspace_1.2-6 gridExtra_2.2.1  tibble_1.2      

How are you calling it in R?

first stan_model and then sampling.