How can I use of az.plot_posterior() for the trace data from ADVI method?

I would like to use the az.plot_ppc() function using the trace data retrieved from the ADVI method.

I used to use az.plot_ppc(idata, num_pp_samples=n) to check the posterior predictive check with my inference data from NUTS; however, it does not work with my trace data.

Please advise.
Thank you.

I am not sure if you want to use plot_posterior or plot_ppc. In either case you’ll need an InferenceData object, but for plot_ppc to work you’ll need both the observed_data and posterior_predictive group.

I assume you did something like approx =, method=advi), so you will need to then run approx.sample(num_samples) in order to get the posterior samples themselves. See Gaussian Processes using numpy kernel — PyMC example gallery for example. The output of .sample will already return and inferencedata.

If you also want to be able to use plot_ppc, you’ll still need to generate posterior predictive samples. Once you have the inferencedata object, you can follow the steps in Prior and Posterior Predictive Checks — PyMC 4.1.4 documentation that show how to run sample_posterior_predictive once you have the posterior samples as an inferencedata object.