# Can sampling a distribution in R result in more wider density or larger range than sampling the same thing in julia?

**URL:** <https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598>\
**Category:** New to Julia\
**Tags:** package\
**Created:** [February 17, 2022, 2:09am UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598 "2022-02-17T02:09:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirror63](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mirror63](https://discourse.julialang.org/u/mirror63)\
**Post date:** [February 17, 2022, 2:09am UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598/1 "2022-02-17T02:09:39Z")

</div>

say I am sampling a model using HMC or Gibbs in Julia, then I produce the same thing in R. Even though the result produced by the sampling have very near mean but I am seeing that my sampling result in Julia has less variance compared to the output that is produced in R, in R the quantiles are more widely spread compared to Julia. And if I increase the number of sampling, the quantiles just gets a bit more stretched in R whereas in Julia, it remains the same. Has anyone faced something similar?

---

<div class="post-metadata">

**Author:** ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)\
**Post date:** [February 17, 2022, 8:17am UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598/2 "2022-02-17T08:17:06Z")

</div>

Interesting, maybe there’s a default value that’s different between R and Julia? Or maybe more samples need to be taken to get to the true distribution? You could try using the same random number generator and random seed to see if they give different results. I think I would need a minimal working example in R and Julia to diagnose further.

---

<div class="post-metadata">

**Author:** ![gragusa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gragusa/32/3547_2.png) [@gragusa](https://discourse.julialang.org/u/gragusa)\
**Post date:** [February 17, 2022, 12:31pm UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598/3 "2022-02-17T12:31:48Z")

</div>

This should not happen. It is either a general bug (not clear whether in the R or Julia code) or a bug arising from different parameterization of the underlying distributions from which Gibbs is sampling (e.g., Gamma, InversePrior using shape and scale vs shape/rate).

---

<div class="post-metadata">

**Author:** ![mirror63](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@mirror63](https://discourse.julialang.org/u/mirror63)\
**Post date:** [February 17, 2022, 12:53pm UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598/4 "2022-02-17T12:53:45Z")

</div>

Yes thanks, I am looking into, chances are what @RobertGregg is true. And thank you again both of you @RobertGregg@gragusa

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 17, 2022, 2:42pm UTC](https://discourse.julialang.org/t/can-sampling-a-distribution-in-r-result-in-more-wider-density-or-larger-range-than-sampling-the-same-thing-in-julia/76598/5 "2022-02-17T14:42:08Z")

</div>

Well… we do tend to be more efficient in the Julia-verse 😉

> **[Efficiency (statistics)](https://en.wikipedia.org/wiki/Efficiency_(statistics))**
>
> In statistics, efficiency is a measure of quality of an estimator, of an experimental design, or of a hypothesis testing procedure. Essentially, a more efficient estimator, experiment, or test needs fewer observations than a less efficient one to achieve a given error performance. 
> An efficient estimator is characterized by a small variance or mean square error, indicating that there is a small deviance between the estimated value and the "true" value. 
> The relative efficiency of two procedures...
