Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added example to plot_hdi using Inference data #1615

Merged
merged 9 commits into from
Mar 30, 2021

Conversation

Rishabh261998
Copy link
Contributor

@Rishabh261998 Rishabh261998 commented Mar 15, 2021

Description

To fix #1479

Checklist

  • Follows official PR format
  • Code style correct (follows pylint and black guidelines)
  • Changes are listed in changelog

@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #1615 (de1dd90) into main (23e14fb) will not change coverage.
The diff coverage is n/a.

❗ Current head de1dd90 differs from pull request most recent head 42afbcc. Consider uploading reports for the commit 42afbcc to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1615   +/-   ##
=======================================
  Coverage   90.91%   90.91%           
=======================================
  Files         108      108           
  Lines       11671    11671           
=======================================
  Hits        10611    10611           
  Misses       1060     1060           
Impacted Files Coverage Δ
arviz/plots/hdiplot.py 92.45% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23e14fb...42afbcc. Read the comment docs.

Comment on lines 118 to 123
>>> data = az.load_arviz_data('radon')
>>> x_data = np.array(data.posterior_predictive.obs_id)
>>> y_data = np.array(data.posterior_predictive.y)
>>> az.plot_hdi(x_data, y_data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if you have looked at how the plot looks like, but obs_id are integer indexes that don't really have any meaning, they should not be used as x values. They are also not continuous, so plotting a continuous hdi band over all observations is not a good idea either.

I think this should be done with the regression1d example better, but it looks like the InferenceData does not have the x values used as predictiors. Going down this path would require solving #1291 and extending the code to get the x data into the inferencedata, which will probably take some time.

As a more immediate solution, I would use simulated data (maybe even the same as above) to create a new inferencedata instead of loading a preexisting one and then use this one to plot the hdi

Copy link
Contributor Author

@Rishabh261998 Rishabh261998 Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense, I too was confused about this bit. I was also thinking of creating a new Inference Object and using that to plot the HDI but as the issue suggested to use pre-computed data so went on with that approach to see if it was possible. So as of now, it is not possible as there are no x values in the posterior predictive or the posterior. Will make the necessary changes. Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note, the x values would be in the constant_data group

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!, could you check @OriolAbril? Thanks

Comment on lines 120 to 122
>>> X = {"x":X}
>>> Y = {"y": Y}
>>> dataset = az.from_dict(posterior=Y, constant_data = X)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
>>> X = {"x":X}
>>> Y = {"y": Y}
>>> dataset = az.from_dict(posterior=Y, constant_data = X)
>>> idata = az.from_dict(posterior_predictive={"y" : Y}, constant_data = {"x" : X})

I'd recommend using this names instead. y is generally used for observed data, and its values will generally be stored in the posterior predictive group instead of the posterior, and I would avoid dataset as a name because the object it represents is an InferenceData as opposed to an xr.Dataset which could be confusing, due to this double meaning of dataset.

@OriolAbril OriolAbril merged commit 3fee46f into arviz-devs:main Mar 30, 2021
utkarsh-maheshwari pushed a commit to utkarsh-maheshwari/arviz that referenced this pull request May 27, 2021
* Added example to plot_hdi using Inference data

* Minor Changes

* linted code

* Added x values to Inference Data Object

* Added example to plot_hdi using Inference data

* Minor Changes

* linted code

* Minor changes

* Updated CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example to az.plot_hdi that shows how to plot hdi from InferenceData posterior or posterior predictive
2 participants