# PPCs in ArviZ?

**URL:** <https://discourse.mc-stan.org/t/ppcs-in-arviz/22176>\
**Category:** Interfaces\
**Tags:** cmdstanpy, arviz\
**Created:** [April 28, 2021, 4:48pm UTC](https://discourse.mc-stan.org/t/ppcs-in-arviz/22176 "2021-04-28T16:48:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shira](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shira/32/14161_2.png) [@shira](https://discourse.mc-stan.org/u/shira)\
**Post date:** [April 28, 2021, 4:48pm UTC](https://discourse.mc-stan.org/t/ppcs-in-arviz/22176/1 "2021-04-28T16:48:29Z")

</div>

Hi ! We are using `CmdStanPy` and `ArviZ` and want to do posterior predictive checks (PPCs).

I see [`plot_ppc()`](https://arviz-devs.github.io/arviz/api/generated/arviz.plot_ppc.html) in arviz, but does arviz also have something like [`ppc_stat()`](https://mc-stan.org/bayesplot/reference/PPC-test-statistics.html) in bayesplot ?

Thanks so much !

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/oriolabril/32/7171_2.png) [@OriolAbril](https://discourse.mc-stan.org/u/OriolAbril)\
**Post date:** [April 28, 2021, 7:19pm UTC](https://discourse.mc-stan.org/t/ppcs-in-arviz/22176/2 "2021-04-28T19:19:12Z")

</div>

It looks like you want to use [`plot_bpv()`](https://arviz-devs.github.io/arviz/api/generated/arviz.plot_bpv.html). `kind="t_stat"` will reproduce the first examples I believe, the docstring has some exmples and some more are available at [Example gallery — ArviZ dev documentation](https://arviz-devs.github.io/arviz/examples/index.html).

Note that you can use `t_stat` argument to pass any function to be used as well as using xarray and numpy to compute the t values and then not use any `t_stat` to use values as is.

A quick example on custom t stat computation (to extend the examples on the docs):

```python
import arviz as az
idata = az.load_arviz_data("radon")
p = (.1, .3, .4, .6, .7, .9)
idata = idata.map(
    lambda ds: ds.assign(qs=ds.y.quantile(p, dim="obs_id")),
    groups="observed_vars"
)
az.plot_bpv(idata, var_names="qs", kind="t_stat", flatten=[])

```

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/9/9c81811807eba27a00412f1aa19b3f4b9a2d3711.png)

the lambda adds a new variable called `qs` with the quantiles, it will have shape `chain, draw, quantile` in posterior predictive and `quantile` in observed\_data `groups="observed_vars"` indicates arviz to apply the same function to posterior predictive and observed\_data groups, `flatten=[]` indicates ArviZ to facet over the present dimensions (the quantile one in this case), by default all dimensions are flattened.

Some of the other options are not possible yet because these kind of plots generally need the ability to choose which dimensions to use to facet and which to reduce but should be possible soon, see [[WIP] Expose skip\_dims/flatten argument #1644 by ericch99 · Pull Request #1676 · arviz-devs/arviz · GitHub](https://github.com/arviz-devs/arviz/pull/1676)
