Create InferenceData from trace and sampled posterior prediction

In Prior and Posterior Predictive Checks, there is an example of visualizing the fit between observations and the posterior predictive samples:

This example combines the trace (as a pm.MultiTrace) and the posterior predictive samples (as a dict) into an arviz.InferenceData object and then passes that object to arviz.plot_ppc().

What if the trace is already an InferenceData object? Is there a way to combine a trace as an InferenceData and posterior predictive samples as a dict into a new InferenceData object? In the long list of ways to create an InferenceData, I could not find one that combines an existing InferenceData and a dict of samples. And az.from_pymc3() does not handle that case:

Or perhaps there is an easier approach to arrive at an InferenceData for arviz.plot_ppc()? (My trace is already an InferenceData thanks to the good advice of @OriolAbril on how to model an intervention.)

You should be able to combine InferenceData.extend with az.from_pymc3, something like:

with model:
    idata = pm.sample(...)
with model:
    ppc = pm.sample_posterior_predictive(...)
    idata_aux = az.from_pymc3(posterior_predictive=ppc)

There is a working example of this in my last blogpost, there is a “posterior predictive” section.

I am leaving links to it wherever I think its relevant for 2 main reasons: first is I tried to make it a good example of the most common questions and issues related to conversion to InferenceData and the second is that I want to get feedback and see its limitations in order to eventually expand the InferenceData cookbook. It currently is a single notebook with one example in each supported PPL and I would like to extend it so each PPL has its own notebook with several examples, something similar to my post.


Note that idata.extend() requires arviz v0.10.0