# Rstan output warning

**URL:** <https://discourse.mc-stan.org/t/rstan-output-warning/15921>\
**Category:** Modeling\
**Created:** [June 13, 2020, 10:42pm UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921 "2020-06-13T22:42:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [June 13, 2020, 10:42pm UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/1 "2020-06-13T22:42:39Z")

</div>

Hi all,

Recently I am running a large rstan program with 4 chains: each with iter=10000; warmup=5000; thin=1

However, I got the following warning message:

There were 16 divergent transitions after warmup. Increasing adapt\_delta above 0.8 may help. See  
[http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmupExamine](http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmupExamine) the pairs() plot to diagnose sampling problems  
The largest R-hat is NA, indicating chains have not mixed.  
Running the chains for more iterations may help. See  
[http://mc-stan.org/misc/warnings.html#r-hatBulk](http://mc-stan.org/misc/warnings.html#r-hatBulk) Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.  
Running the chains for more iterations may help. See  
[http://mc-stan.org/misc/warnings.html#bulk-essTail](http://mc-stan.org/misc/warnings.html#bulk-essTail) Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.  
Running the chains for more iterations may help. See  
[http://mc-stan.org/misc/warnings.html#tail-ess](http://mc-stan.org/misc/warnings.html#tail-ess)

I believe that I have ran enough number of simulations and the Rhat for the paramters in the model are all like 1.00x (less than 1.01). But I am still confused about the following two questions:

1. Should I ignore the warning message?
2. Some paramters have relatively small n\_eff, such as 3000 but in total I have ran 60000 simulations, will it just because of randomness or my model is misspecified?

Thx!

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [June 13, 2020, 10:43pm UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/2 "2020-06-13T22:43:38Z")

</div>

Also when I repeated the sampling, some of the smallest n\_eff have changed from 3000 to around 10000, which makes me quite confused…

---

<div class="post-metadata">

**Author:** ![ssp3nc3r](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ssp3nc3r/32/120_2.png) [@ssp3nc3r](https://discourse.mc-stan.org/u/ssp3nc3r)\
**Post date:** [June 14, 2020, 12:04am UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/3 "2020-06-14T00:04:59Z")

</div>

You should not ignore the warnings, and you probably should not need to run that many iterations. It’s hard to say More without seeing how you specified your model.

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [June 14, 2020, 4:27am UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/4 "2020-06-14T04:27:14Z")

</div>

Thx!

Also I found that one of the paramters has n\_eff 66314, which is greatly than the total number of simulations (60000). Does it mean that my calculation is wrong?

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [June 14, 2020, 9:51am UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/5 "2020-06-14T09:51:03Z")

</div>

> [@stan\_beginer](#):
>
> one of the paramters has n\_eff 66314, which is greatly than the total number of simulations (60000). Does it mean that my calculation is wrong?

That is not an error. Effective sample size [can be larger than total sample size](https://statmodeling.stat.columbia.edu/2018/01/18/measuring-speed-stan-incorrectly-faster-thought-cases-due-antithetical-sampling/).

> [@stan\_beginer](#):
>
> when I repeated the sampling, some of the smallest n\_eff have changed from 3000 to around 10000

The estimated effective sample size is going to vary from run to run. That’s especially true when mixing is slow because then the adaptation is less reliable.

---

<div class="post-metadata">

**Author:** ![stan\_beginer](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@stan\_beginer](https://discourse.mc-stan.org/u/stan_beginer)\
**Post date:** [June 14, 2020, 1:14pm UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/6 "2020-06-14T13:14:35Z")

</div>

Thanks so much!

May I ask that is Rstan has some funtion like set.seed() so that I could make sure that every time I ran some Rstan code the output will be reproducible?

---

<div class="post-metadata">

**Author:** ![FJCC](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/fjcc/32/6653_2.png) [@FJCC](https://discourse.mc-stan.org/u/FJCC)\
**Post date:** [June 14, 2020, 5:41pm UTC](https://discourse.mc-stan.org/t/rstan-output-warning/15921/7 "2020-06-14T17:41:00Z")

</div>

The _stan()_ function in rstan has a seed parameter. The documentation says:

`seed: The seed for random number generation. The default is generated from 1 to the maximum integer supported by **R** on the machine. Even if multiple chains are used, only one seed is needed, with other chains having seeds derived from that of the first chain to avoid dependent samples. When a seed is specified by a number, `as.integer` will be applied to it. If `as.integer` produces `NA`, the seed is generated randomly. The seed can also be specified as a character string of digits, such as `"12345"` , which is converted to integer.

Using **R**'s `set.seed` function to set the seed for Stan will not work.`
