# Convergence quality API

**URL:** <https://discourse.pymc.io/t/convergence-quality-api/5007>\
**Category:** Questions\
**Created:** [May 4, 2020, 1:38pm UTC](https://discourse.pymc.io/t/convergence-quality-api/5007 "2020-05-04T13:38:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwassner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/hwassner/32/527_2.png) [@hwassner](https://discourse.pymc.io/u/hwassner)\
**Post date:** [May 4, 2020, 1:38pm UTC](https://discourse.pymc.io/t/convergence-quality-api/5007/1 "2020-05-04T13:38:57Z")

</div>

Hi,

Is there a way to get the convergence check informations programatically ?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/d/d22343d436395030d950d3cb9c304f43a4bbd717.png)  
I mean having these information (number of diverging samples, rhat, etc…) in variables in order to use them in scripts …

Thanks for your help.  
H.

---

<div class="post-metadata">

**Author:** ![ckrapu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ckrapu/32/1366_2.png) [@ckrapu](https://discourse.pymc.io/u/ckrapu)\
**Post date:** [May 4, 2020, 9:29pm UTC](https://discourse.pymc.io/t/convergence-quality-api/5007/2 "2020-05-04T21:29:57Z")

</div>

Yup - you can extract the \hat{R} values using `pm.summary` while the presence of divergences can be extracted directly from the trace. Here’s an example:

```auto
with pm.Model() as model:
    x = pm.Normal('x')
    trace = pm.sample()
    
    n_diverging = trace['diverging'].sum()
    rhat = pm.summary(trace)['r_hat']

```

To obtain other statistics from the sampler, you can see the variables listed via `trace.stat_names`.
