mitchelloharawild / distributional

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

Updating the Formatting of dist_mixture #112

Closed statasaurus closed 3 weeks ago

statasaurus commented 1 month ago

This is a small pull request to update the formatting for mixture distributions. It is hard for users to understand the contents of the mixture when only given the number of components so I have added information about the components. The new format method creates the following output

image

If there is a concern about the length I am happy to use {pillar} so it can dynamically print, but I didn't want to add the dependancy without running it by you.

mitchelloharawild commented 1 month ago

Thanks, I don't mind a wider format method for mixture distributions. Definitely would want to use {pillar} as a Suggest, with the methods dynamically registered in .onLoad().

I do think all of the parameters of the mixture should be inside the mixture parenthesis, i.e. mixture(<params>). A denser display would also be preferable.

Perhaps mixture(n=2) for small widths, and mixture([w=0.5: N(0,1)], [w=0.5: t(10, 0, 1)]) for wider widths? Any other dense suggestions are welcomed.

mjskay commented 1 month ago

What about something that echoes the cdf/density formula, like mixture(0.5*N(0,1) + 0.5*t(10, 0, 1))?

mitchelloharawild commented 1 month ago

I'd want to be a bit careful not to confuse mixtures with convolutions (#106), but perhaps the short form of w*<dist> can be used here? Example: mixture(0.5*N(0,1), 0.5*t(10, 0, 1))?

mjskay commented 1 month ago

Oh yeah good point, I like that instead.

statasaurus commented 1 month ago

That seems great. I will update my pull request soon

statasaurus commented 1 month ago

So I have updated the print message to match what we discussed. I wasn't able to get the dynamic length adjustment working. {pillar} uses the class of the object and because all the distributions have the same class the formatting method would have to cover all the distributions.

mitchelloharawild commented 1 month ago

Instead of using {pillar}, could you update it to use a width = getOption("width") option? This option should ensure that at most 1 line is used per distribution.

For example: image

statasaurus commented 1 month ago

So I ended up with an option in the middle. I am using pillar and the width option. Basically all the other formats don't take width in as an option it was actually easy to apply to all the other distributions. Now it looks something like this:

image
statasaurus commented 3 weeks ago

@mitchelloharawild Sorry I realised I forgot to update the tests and tag you in this. But I think it should be good to go now