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

Support multidimensional dists / rvars in point_interval #111

Open
mjskay opened this issue Nov 19, 2021 · 5 comments
Open

Support multidimensional dists / rvars in point_interval #111

mjskay opened this issue Nov 19, 2021 · 5 comments

Comments

@mjskay
Copy link
Owner

mjskay commented Nov 19, 2021

Pinging off of #14 (comment)

Probably add a column for the index

@mitchelloharawild
Copy link

I've pushed an update to {fabletools} onto CRAN yesterday which prepares for the next release of {distributional}. It doesn't use {ggdist} for the graphics yet as the existing functionality being replaced supports multivariate distributions. If you'd like to push {ggdist} to CRAN soon, then I can send {distributional} to CRAN.

I think this is the last issue preventing {fabletools} from using {ggdist}, and removing the {ggplot2} import from {distributional}. If it could be included in the next release that would allow me to swap over to {ggdist} sooner, but if not I still think releasing the updates to {ggdist} and {distributional} is worthwhile now.

@mjskay mjskay added this to the Next release milestone Nov 30, 2021
@mjskay
Copy link
Owner Author

mjskay commented Nov 30, 2021

Cool sounds good, I'll push a minor release of {ggdist} soon to ensure forward compatibility with {distributional} and then prioritize this issue in the next major release.

@mjskay
Copy link
Owner Author

mjskay commented Nov 30, 2021

@mitchelloharawild ggdist 3.0.1, which should be forward-compatible with the new {distributional}, is on its way to cran. Please let me know if you run into any issues with it and I will push a new version.

@mjskay
Copy link
Owner Author

mjskay commented Jan 15, 2022

@mitchelloharawild I'm working through some last issues in prep for a new release and I want to make sure I hit the couple of things you need, including this one. Is there anything else not on this milestone that would be helpful?

@mjskay
Copy link
Owner Author

mjskay commented Jan 17, 2022

@mitchelloharawild a potential solution to this is now on master: the point_interval() family of functions will now produce a .index column for multivariate distribution objects and rvars. Example:

library(ggplot2)
library(dplyr)
library(distributional)
library(ggdist)

tibble(
  x = c(
    dist_multivariate_normal(list(c(1:4)), list(diag(4))),
    dist_normal()
  ),
  y = c("a","b")
) %>%
  median_qi(x, .width = c(.66, .95))
#> # A tibble: 10 x 8
#>        x y     .index  .lower .upper .width .point .interval
#>    <dbl> <chr>  <int>   <dbl>  <dbl>  <dbl> <chr>  <chr>    
#>  1     1 a          1  0.0458  1.95    0.66 median qi       
#>  2     2 a          2  1.05    2.95    0.66 median qi       
#>  3     3 a          3  2.05    3.95    0.66 median qi       
#>  4     4 a          4  3.05    4.95    0.66 median qi       
#>  5     0 b         NA -0.954   0.954   0.66 median qi       
#>  6     1 a          1 -0.960   2.96    0.95 median qi       
#>  7     2 a          2  0.0400  3.96    0.95 median qi       
#>  8     3 a          3  1.04    4.96    0.95 median qi       
#>  9     4 a          4  2.04    5.96    0.95 median qi       
#> 10     0 b         NA -1.96    1.96    0.95 median qi

Created on 2022-01-16 by the reprex package (v2.0.1)

This can be used with (e.g.) geom_pointinterval() by mapping .index to something:

tibble(
  x = dist_multivariate_normal(list(c(1:4)), list(diag(4))),
  y = c("a","b")
) %>%
  median_qi(x, .width = c(.66, .95)) %>%
  ggplot(aes(x, xmin = .lower, xmax = .upper, y = .index)) +
  geom_pointinterval()

Created on 2022-01-16 by the reprex package (v2.0.1)

Or since stat_pointinterval() uses the point_interval() functions internally, it also generates an .index column that can be mapped after stats are calculated:

tibble(
  x = c(
    dist_multivariate_normal(list(c(1:4)), list(diag(4))),
    dist_normal()
  ),
  y = c("a","b")
) %>%
  ggplot(aes(xdist = x, y = y, group = stat(.index))) +
  stat_pointinterval(position = "dodge")

Created on 2022-01-16 by the reprex package (v2.0.1)

Some limitations:

  • currently this only works with intervals; it can't calculate CDFs or densities from multivariate distributions. That is enough that stat/geom_lineribbon, stat/geom_pointinterval, and stat/geom_interval should work at least.
  • only quantile intervals currently work for this, not HDIs.

Let me know if this is sufficient for what you need. I think this is the last issue before I draft a new release.

@mjskay mjskay removed this from the Next release milestone May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants