Using trace data for posterior calculations

When I am using trace data for posterior calculations like -

  1. generating trace summary - az.summary(trace)
  2. Converting to a dataframe - az.convert_to_inference_data(obj=trace).to_dataframe(include_coords=False,groups=“posterior”)
  3. Plotting trace - az.plot_trace(trace)

For each of these functions, I am getting the following error -

Got error No model on context stack. trying to find log_likelihood in translation.

The error goes away if I give the with model context like this -

with model_factory(df):
az.plot_trace(trace)

Can someone explain what that error is? and is it required to give context stack while using trace for posterior calculations?

ArviZ doesn’t work with the trace object directly, it converts to InferenceData format (since 4.x, pymc returns InferenceData by default). For plotting or summary with InferenceData, the model context isn’t necessary, but for conversion it is. For more in depth explanation about the conversion ans integration between arviz and pymc see PyMC3 with labeled coords and dims — Oriol unraveled