mitchelloharawild / distributional

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

Add a function to access the distributional objects inside a mixture distribution #113

Open statasaurus opened 1 month ago

statasaurus commented 1 month ago

It would be very helpful to have a function would return a list of distributional objects that make up a mixture distribution so that conjugacy can be used to calculate posteriors where possible. In Pharma we often use a mixture of normals to approximate other distributions for simulation work.


I have tried working around it like this:

x <- dist_mixture(dist_normal(), dist_normal(sigma = 10), weights = c(0.5, 0.5))
y <- parameters(x)$dist[[1]]
dist_mixture(!!!y, weights = parameters(x)$w[[1]])

But, the problem is the list isn't a list of distributional objects, so when you try to reconstitute it into a mixture distribution it doesn't work.

Sorry for so many issues. We are working on a bayesian dynamic borrowing package and your package is nearly perfect, we just need a few modifications

statasaurus commented 18 hours ago

If I wrote this function would it be something you want to include in your package? If not I am happy to close the issue and I will work on this elsewhere