-
Notifications
You must be signed in to change notification settings - Fork 232
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
Feature request/idea: option to plot highest-density intervals #153
Comments
This would be great! Do you know if the arviz functions handle weighted samples properly? That would be crucial for this to be included. I'm probably not going to be able to get to this too soon, but I'd be happy to collaborate on a PR. |
The arviz.hdi function does not have an option for including weights, so if that's crucial to include here, it would involve new code (though possibly with some borrowing of ideas and/or code from arviz). Looking at the arviz code and the algorithm for how it calculates HDI, it's not obvious to me that it lends itself easily to bringing weights in. The algorithm looks like this:
To do this with weights, you can't follow quite the same logic because the intervals with the same weighted fractional probability wouldn't all have the same length. But maybe you could do something along these lines:
For step 4, I don't see any obvious way to vectorize, so it could be slow for large arrays (but the larger the probability interval is, the fewer subarrays there are to consider). Does this logic seem reasonable? I guess the upside here is that if it's new code, it is not dependent on having arviz installed. |
This does sound like the right algorithm to me, and I'd be open to including something like this. We already have a custom Line 388 in c0c6264
because the numpy An alternative would be to add a tutorial to the documentation that demonstrates this procedure using ArviZ directly (it might be worth using the |
Now that arviz is an optional dependence, it would be nice to have the option to easily plot the highest-density intervals (from arviz.hdi) on the histograms rather than percentiles - in the case of asymmetric distributions, I find these more informative than the current quantiles behavior (though in the limit of a symmetric distribution they would be the same).
If you think this is a useful addition, I'd be happy to write up a PR. Before I do that, though, I thought I'd ask:
Here's a quick example showing the difference with symmetric vs. asymmetric distributions - HDI 50% interval is in green, vs. 25% and 75% quantiles.
The text was updated successfully, but these errors were encountered: