mitchelloharawild / distributional

Vectorised distributions for R
https://pkg.mitchelloharawild.com/distributional
GNU General Public License v3.0
96 stars 15 forks source link

Improve handling of continuous distributions with infinite density at points #125

Open mitchelloharawild opened 2 weeks ago

mitchelloharawild commented 2 weeks ago

The density at a discrete point in the mixture should be Inf, cdf is fine.

library(ggdist)
library(distributional)
library(ggplot2)
ggplot(NULL, aes(xdist = dist_mixture(dist_normal(), dist_poisson(3), weights = c(0.5, 0.5)))) +
  stat_slab(n = 1001, slab_type = "pdf")

ggplot(NULL, aes(xdist = dist_mixture(dist_normal(), dist_poisson(3), weights = c(0.5, 0.5)))) +
  stat_slab(n = 1001, slab_type = "cdf")

dist_poisson(3) |> 
  support()

dist_normal(3) |> 
  support()

dist_mixture(dist_normal(), dist_poisson(3), weights = c(0.5, 0.5)) |> 
  density(c(3, 3.3))
mitchelloharawild commented 1 week ago

Probably safest for now is to disallow mixing distributions with different classes (e.g. double, integer, character). However this is still a problem for things like dist_inflated() with continuous distributions, so I've made the title more generic.