mitchelloharawild / distributional

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

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

Open statasaurus opened 5 months ago

statasaurus commented 5 months 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 4 months 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