# Is it ok to ravel() over all chains/draws to compare the posteriors of two means?

**URL:** <https://discourse.pymc.io/t/is-it-ok-to-ravel-over-all-chains-draws-to-compare-the-posteriors-of-two-means/16282>\
**Category:** version agnostic\
**Created:** [December 21, 2024, 8:00am UTC](https://discourse.pymc.io/t/is-it-ok-to-ravel-over-all-chains-draws-to-compare-the-posteriors-of-two-means/16282 "2024-12-21T08:00:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bayesian\_padawan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/bayesian_padawan/32/8761_2.png) [@bayesian\_padawan](https://discourse.pymc.io/u/bayesian_padawan)\
**Post date:** [December 21, 2024, 8:00am UTC](https://discourse.pymc.io/t/is-it-ok-to-ravel-over-all-chains-draws-to-compare-the-posteriors-of-two-means/16282/1 "2024-12-21T08:00:04Z")

</div>

Hi,

in some other discussion, I read something that the ravelling over chains and draws of posteriors should be avoided. I didn’t fully understand the point and maybe I misunderstood this. Therefore, I would like to clarify this for me with the simple example of the comparison of two estimated normal means.

I estimated these means and can access the posterior results in `idata["posterior"]["mu_A"]` and `idata["posterior"]["mu_B"]`.

To compare the two means, I could now do this:

```auto
posterior_mu_A = idata_ab_test["posterior"]["mu_A"].values.ravel()
posterior_mu_B = idata_ab_test["posterior"]["mu_B"].values.ravel()

```

When I plot these data it could look like this:

 ![grafik](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/c/cefd7bcc3aafcc62bce18fc4778c7eb969313ba7.png)

I could then continue and ask myself “What is the probability that the difference between the two means is greater then 0.5?” and write the following code to get this probability:

```auto
epsilon = 0.5
diff = posterior_mu_A - posterior_mu_B
mean_diff = np.mean(diff)
prob_diff_greater_epsilon = np.mean(diff > epsilon)

```

This could be visualized like this:

 ![grafik](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/4/4b669dd3ba365d4408c63e483b3a10f1873c0551.png)

My question now is if it was “correct” to ravel() the posterior data in the first place? I sort of handle the ravelled data like independent draws of the same distribution. Assumed that the metrics of all chains look ok, is this assumption correct or is there any argument that this should be avoided?

Thanks for any hints (and have a nice christmas time!)  
Matthias

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [December 21, 2024, 8:05am UTC](https://discourse.pymc.io/t/is-it-ok-to-ravel-over-all-chains-draws-to-compare-the-posteriors-of-two-means/16282/2 "2024-12-21T08:05:30Z")

</div>

Yes ravelling is fine. The draws from the different chains should be statistically equivalent if the sampler converged
