Hi ! We are using CmdStanPy
and ArviZ
and want to do posterior predictive checks (PPCs).
I see plot_ppc()
in arviz, but does arviz also have something like ppc_stat()
in bayesplot ?
Thanks so much !
Hi ! We are using CmdStanPy
and ArviZ
and want to do posterior predictive checks (PPCs).
I see plot_ppc()
in arviz, but does arviz also have something like ppc_stat()
in bayesplot ?
Thanks so much !
It looks like you want to use plot_bpv()
. 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.
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):
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=[])
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