Thanks to @cluhmann for pointing me to the post! Following the advice there, I managed to partially resolve the issue—I changed my code like this:
def analysis(self, trace):
# result
az.plot_trace(trace)
# print
print(az.summary(trace))
az.plot_forest(trace, r_hat=True)
az.plot_posterior(trace)
with self.model:
check = pm.sample_posterior_predictive(trace,extend_inferencedata=True)
fig1, ax1 = plt.subplots()
fig2, ax2 = plt.subplots()
ax = az.plot_ppc(check, alpha=0.025, kind='kde', observed=True, ax=[ax1,ax2])
for i, ax in enumerate(ax.flat):
ax.set_xlim([-0.002,0.002])
plt.show()
now the observed data curve is no longer a straight line. However, I’m still facing some problems:
-
Despite ‘fixing’(actually, it’s just amplification) the observed data curve, the other posterior predictive curves are still appearing as single straight lines. This seems unusual, and I’m not sure why only the observed data was corrected while the other two remain problematic.Was my data processing methods towards
covid_newandinfluenza_newwent wrong? -
Although the observed data curve is now showing properly in the
az.plot_ppcoutput, it doesn’t match the curve I get when I plot the observed data directly using the same data processing code. The two curves it should be is like this:
If you need more and more detailed code, please feel free to let me know.
Thanks again for your help! I’ve been struggling with this issue for weeks
, any insights or suggestions on how to troubleshoot this would be greatly appreciated.

