# Slice sampler: how many chains and draws should I choose?

**URL:** <https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713>\
**Category:** ML/Bayesian estimation\
**Created:** [29 December 2022 19:13 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713 "2022-12-29T19:13:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Romero](https://forum.dynare.org/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@Romero](https://forum.dynare.org/u/Romero)\
**Post date:** [29 December 2022 19:13 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/1 "2022-12-29T19:13:02Z")

</div>

Dear all,  
I was wondering where I can find guidance on the use of the slice sampler. The only paper I am aware of is the 2015 Planas/ Ratto/ Rossi paper  
( [https://archives.dynare.org/DynareConference2015/papers/Ratto\_Planas\_Rossi.pdf](https://archives.dynare.org/DynareConference2015/papers/Ratto_Planas_Rossi.pdf) ), which is incomplete and does not offer practical guidance.  
My understanding from the attached presentation from a course that a colleague took at the JRC is that the basic principle is to have more chains but fewer draws (since the chains converge much faster than with the RWMH), and that you do it twice: Once to get a covariance matrix (with an even lower mh replic), and then again with the rotated option (slide 17).  
[Slice\_GSA\_Course\_2019.pdf](https://forum.dynare.org/uploads/short-url/oq8KKgeTh5zwrbxMcQbydvncRrB.pdf) (2.1 MB)

But which combination of chains and draws is “okay”, is there rule of thumb? In the presentation there seems to be one example with 4 chains and 100 draws (slide 25, if I understand correctly). But then there is also one example suggested for parallel implementation, with mh blocks=250 (!!), and a much smaller mh\_replic numbers for both runs of the sampler (see slide 27).

Finally, with the slice sampler, do I still need to care about the value of mh\_jscale and the acceptance ratio?

Just to give some further background for my question (in case it is relevant): The reason I am interested in the slice sampler is that I ran into the problem that " (minus) the hessian matrix at the “mode” is not positive definite!=\> posterior variance of the estimated parameters are not positive." (although all the posterior standard deviations are real values (not complex numbers)) when using the mode finder. I should mention that I am using the occbin estimation (with the piecewise Kalmann filter), I have already tried mode finders 1 and 5, and that for the standard estimation (without occbin), computing the hessian poses no problem. Also, the parameter estimates are very close to the estimation without Occbin. Unfortunately, I am not able to do the mode\_check for the Occbin estimation properly since the machine runs out of memory after having produced the mode\_check graphs for some of the parameters (for one of the parameters for which the graph is produced, the surface of the posterior is very rough).

Best wishes,  
Ansgar

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [30 December 2022 10:15 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/2 "2022-12-30T10:15:46Z")

</div>

@rattoma should be able to answer most of the initial questions.

I am a bit puzzled by the mode\_check-problems. Could you maybe provide me with the codes and the mode-file to see where the problems come from.

---

<div class="post-metadata">

**Author:** ![Romero](https://forum.dynare.org/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@Romero](https://forum.dynare.org/u/Romero)\
**Post date:** [30 December 2022 18:00 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/3 "2022-12-30T18:00:38Z")

</div>

Hi Johannes,  
sure I am attaching them. You need to type " dynare E\_obc\_e " The .mod files are a bit messy, I apologize. The estimation command is in the E\_obc\_e.mod files. Many thanks!  
Best wishes,  
Ansgar  
[mode\_check\_problem.zip](https://forum.dynare.org/uploads/short-url/1d9tLjnkjlAZlqBCPKeLOQIp5Kx.zip) (2.0 MB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [9 January 2023 17:47 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/4 "2023-01-09T17:47:42Z")

</div>

Hi,  
I cannot reproduce the `mode_check`-problems you report in the unstable version. How much memory does your machine have?  
The message

> (minus) the hessian matrix at the “mode” is not positive definite!=\> posterior variance of the estimated parameters are not positive.

is not about the estimated standard deviation of your shocks, but the estimated variances of all the parameter estimates. The fact that the Hessian at the mode is not positive definite means that it’s not a proper covariance matrix at the mode.

The message I am getting is

> warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 7.022761e-17

in `occbin.mkdatap_anticipated_dyn.m`. This suggests your estimation ran to a pathological region of the parameter space.

---

<div class="post-metadata">

**Author:** ![Romero](https://forum.dynare.org/letter_avatar_proxy/v4/letter/r/b782af/32.png) [@Romero](https://forum.dynare.org/u/Romero)\
**Post date:** [10 January 2023 10:01 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/5 "2023-01-10T10:01:56Z")

</div>

Hi Johannes,  
thank you, I have attached a screenshot from the system information. The installed physical memory is 32 GB. “Available physical memory” is 18,6 GB  
 ![image](https://forum.dynare.org/uploads/default/original/2X/0/0b7cc7a9c95bce81e50a866a4300ee27a191adff.png)

Yes I got that error message as well during mode check, in the past I also sometimes got it during the mode-finding procedure with fmincon in combination with Occbin. What do you mean with pathological region of the parameter space? Is that a region where Occbin cannot find a solution?  
Best,  
Ansgar

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [15 January 2023 18:03 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/6 "2023-01-15T18:03:07Z")

</div>

I ran the code with the same memory and found no issues. With pathological I mean that OccBin has a hard time computing the solution and works with close to singular matrices.

---

<div class="post-metadata">

**Author:** ![dh.murakami](https://forum.dynare.org/letter_avatar_proxy/v4/letter/d/58956e/32.png) [@dh.murakami](https://forum.dynare.org/u/dh.murakami)\
**Post date:** [5 August 2026 14:08 UTC](https://forum.dynare.org/t/slice-sampler-how-many-chains-and-draws-should-i-choose/21713/7 "2026-08-05T14:08:48Z")

</div>

I’m bumping this because I also have questions about a production-worthy OccBin estimation run using the `slice` sampler.

@rattoma suppose for a model with approx. 50 estimated parameters, would you advocate for two runs:  
**run 1**  
`mh_nblocks=250; mh_replic=30;`  
**run\_2**  
`mh_nblocks=250; mh_replic=15; posterior_sampler_options = ('rotated',1,'use_mh_covariance_matrix',1);`  
(with `load_mh_file` in `estimation();`)
