# Az.plot\_compare returning KeyError: 0 (from Statistical Rethinking lec 7)

**URL:** <https://discourse.pymc.io/t/az-plot-compare-returning-keyerror-0-from-statistical-rethinking-lec-7/11673>\
**Category:** v5\
**Tags:** arviz\
**Created:** [March 22, 2023, 7:13am UTC](https://discourse.pymc.io/t/az-plot-compare-returning-keyerror-0-from-statistical-rethinking-lec-7/11673 "2023-03-22T07:13:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jajaja18](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jajaja18/32/6059_2.png) [@jajaja18](https://discourse.pymc.io/u/jajaja18)\
**Post date:** [March 22, 2023, 7:13am UTC](https://discourse.pymc.io/t/az-plot-compare-returning-keyerror-0-from-statistical-rethinking-lec-7/11673/1 "2023-03-22T07:13:01Z")

</div>

Hi, i’m following the Statistical Rethinking textbook with the PYMC code examples [[here](https://github.com/pymc-devs/pymc-resources/blob/main/Rethinking_2/Chp_07.ipynb)]

I’m following the code example (output 17) and needed to produce the az.compare\_plot. I ended up with a KeyError: 0 after running and obtained the following plot which is not the same as the notebook:

> samples\_dict = {1: first\_sample, 2: second\_sample, 3: third\_sample, 4: fourth\_sample}  
> compare\_df = az.compare(samples\_dict, scale=“deviance”, ic=“waic”)  
> compare\_df  
> az.plot\_compare(compare\_df)

| | rank | elpd\_waic | p\_waic | elpd\_diff | weight | se | dse | warning | scale |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 2 | 0 | 85.855459 | 5.405649 | 0.000000 | 0.588597 | 18.897129 | 0.000000 | True | deviance |
| 3 | 1 | 85.948867 | 5.572997 | 0.093408 | 0.411403 | 17.488824 | 1.793653 | True | deviance |
| 1 | 2 | 86.906720 | 4.735193 | 1.051261 | 0.000000 | 17.724246 | 2.073266 | True | deviance |

![image](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/8/8dde4f4a18424efad79a25f5617cf5e52aa671b8.png)

I’m guessing the version may be the issue as the notebook uses pymc v3 and an older arviz version.

Version i’m using:

pymc: 5.0.1  
arviz: 0.14.0

Appreciate help on this, thanks!

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [March 23, 2023, 8:40am UTC](https://discourse.pymc.io/t/az-plot-compare-returning-keyerror-0-from-statistical-rethinking-lec-7/11673/2 "2023-03-23T08:40:24Z")

</div>

Does it also happen with newer arviz versions? I think that was a bug in old arviz versions
