Add example to az.plot_hdi that shows how to plot hdi from InferenceData posterior or posterior predictive
See original GitHub issueTell us about it
The az.plot_hdi
docs only show how to plot the hdi from synthetic data. What would be nice is if it also shows users how to plot the hdi from an az.InferenceData
as thats the standard data representation most people will be working with.
Thoughts on implementation
Use one of the precomputed datasets that has a posterior predictive group and create a plot.
Here’s an example of loading a dataset with posterior predictive group https://arviz-devs.github.io/arviz/api/generated/arviz.plot_ppc.html
Here’s an (unrelated) example where PyMC3 generates a trace and posterior predictive group and its used with az.plot_hdi
with pm.Model() as model_linear:
β = pm.Normal('β', sd=10, shape=2)
μ = pm.Deterministic('μ', pm.math.dot(babies[["Intercept", "Month"]], β))
ϵ = pm.HalfNormal('ϵ', sd=10)
length = pm.Normal('length', mu=μ, sd=ϵ, observed=babies.Length)
linear_trace = pm.sample(2000, tune=4000)
linear_ppc = pm.sample_posterior_predictive(inf_data_linear)
inf_data_linear = az.from_pymc3(trace=linear_trace, posterior_predictive= linear_ppc)
fig, ax = plt.subplots()
ax.set_ylabel("Length")
ax.set_xlabel("Month");
μ_m = inf_data_linear.posterior["μ"].values.reshape(-1, babies.Length.shape[0]).mean(axis=0)
ax.plot(babies.Month, μ_m, c='C4')
az.plot_hdi(babies.Month, inf_data_linear.posterior_predictive["length"], hdi_prob=.94, ax=ax)
ax.plot(babies.Month, babies.Length, 'C0.', alpha=0.1)
plt.savefig('img/Baby_Length_Linear_Fit.png', dpi=300)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Source code for arviz.plots.hdiplot
This example shows how to use :func:`~arviz.hdi` to precalculate the values and ... Here we use the posterior predictive to plot the HDI...
Read more >Trying to plot posterior Predictive plot using az ...
Hello I am using CmdStanModel using Python. The model has run well and I have all the summary I need. Here is the...
Read more >arviz.plot_ppc — ArviZ 0.14.0 documentation
InferenceData object containing the observed and posterior/prior predictive data. kind: str. Type of plot to display (“kde”, “cumulative”, or “scatter”).
Read more >Summarize inference data (HDI) - PyMC Discourse
Hi! When I summarize the statistics of my inference data using az.summary(), one of the columns of the dataframe is hdi_3%.
Read more >Pymc3 And Arviz: Visualizing Highest Posterior Density For ...
Calculate highest density interval HDI of array for given probability. Examples. Plot HDI interval of simulated regression data using y argument: >>>. Plot...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Using precomputed data set
yes, assigning it to you