You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
type_density() using the new type_data/type_draw system #243
The existing density logic is quite complicated, because we make special allowances for tinyplot(density(x)). I'm not sure that this exception is worth it anymore, so it might be worth axing and enforcing tinyplot(x, type = "density") to maintain internal simplicity. Will investigate when I have time.
Reacted by Achim Zeileis, Vincent Arel-Bundock and devSJR
I've run up against this issue a few times lately, so will take a crack at it before submitting v0.3.0 to CRAN.
(If it turns out to be too complicated for solving in a reasonable time, I'll just submit the new release without it. But hopefully there's a simple solution.)
Thanks for the write-up and apologies for the 12" version of Simon & Garfunkel playing over the last weeks. (You know...The Sound of Silence...) I took some time off over the holidays.
Coming back to this issue now I played around with your examples above as well as some artificial data I simulated from various normal distributions with different means and/or variances. Based on this my impression is that only A or D should be used.
B is problematic in settings where I have subgroups with similar variances but (very) different means. Computing the bandwidth from the joint sample will lead to inflated values, e.g.,
This will dampen the density curve as you can also see in the red line for your mtcars example.
C is clearly inferior to D when the subgroups have very different sizes because small groups might change the bandwidth estimates too much.
For A vs. D I think that A is probably the safer default. In cases where the bandwidth from the different groups are roughly similar, strategy D will stabilize the bandwidth estimates. But in cases where the bandwidth is very different (e.g., because variances are very different), D might be a poor compromise and using separate bandwidths from A would be better.
So, in short, my current thinking is that A should be the default but it would be nice if D were easy to do as well.
Thinking some more about this: B may be a useful strategy when the groups overlap a lot, i.e., all have similar means and variances. So adding this as another option might also be nice to have sometimes...
For posterity, the dev version of tinyplot now defaults to (A), but makes options (B) and (D) available to users via the type_density(joint.bw = <arg>) argument.
Activity
grantmcdermott commentedon Nov 7, 2024
Nice. Was just thinking about this!
The existing density logic is quite complicated, because we make special allowances for
tinyplot(density(x)). I'm not sure that this exception is worth it anymore, so it might be worth axing and enforcingtinyplot(x, type = "density")to maintain internal simplicity. Will investigate when I have time.vincentarelbundock commentedon Nov 8, 2024
Yes, I think that small amount of breakage is a good idea while the package is still young. We want to start with strong standards.
grantmcdermott commentedon Nov 12, 2024
I've run up against this issue a few times lately, so will take a crack at it before submitting v0.3.0 to CRAN.
(If it turns out to be too complicated for solving in a reasonable time, I'll just submit the new release without it. But hopefully there's a simple solution.)
grantmcdermott commentedon Dec 21, 2024
@zeileis a question for you (and picking up part of a discussion originally started in #271):
Q: How do you think the joint bandwidth should be calculated for grouped density plots?
To my mind there are four options:
Here's a quick manual implementation of each of these four options, using an
mtcarsdemo example.Right now, we are using (C), but I'm not sure that it is optimal.
FWIW, this is the equivalent ggplot2 result. It looks like they're just taking the simplest approach (A) and not using any kind of joint bandwidth.
zeileis commentedon Jan 8, 2025
Thanks for the write-up and apologies for the 12" version of Simon & Garfunkel playing over the last weeks. (You know...The Sound of Silence...) I took some time off over the holidays.
Coming back to this issue now I played around with your examples above as well as some artificial data I simulated from various normal distributions with different means and/or variances. Based on this my impression is that only A or D should be used.
B is problematic in settings where I have subgroups with similar variances but (very) different means. Computing the bandwidth from the joint sample will lead to inflated values, e.g.,
This will dampen the density curve as you can also see in the red line for your
mtcarsexample.C is clearly inferior to D when the subgroups have very different sizes because small groups might change the bandwidth estimates too much.
For A vs. D I think that A is probably the safer default. In cases where the bandwidth from the different groups are roughly similar, strategy D will stabilize the bandwidth estimates. But in cases where the bandwidth is very different (e.g., because variances are very different), D might be a poor compromise and using separate bandwidths from A would be better.
So, in short, my current thinking is that A should be the default but it would be nice if D were easy to do as well.
grantmcdermott commentedon Jan 8, 2025
Excellent, thanks for the deep dive @zeileis! I'll aim to incorporate those changes into #284 when I get a chance.
vincentarelbundock commentedon Jan 8, 2025
@zeileis love the thoroughness. Very, very good stuff.
zeileis commentedon Jan 9, 2025
Thinking some more about this: B may be a useful strategy when the groups overlap a lot, i.e., all have similar means and variances. So adding this as another option might also be nice to have sometimes...
grantmcdermott commentedon Jan 9, 2025
For posterity, the dev version of tinyplot now defaults to (A), but makes options (B) and (D) available to users via the
type_density(joint.bw = <arg>)argument.Created on 2025-01-08 with reprex v2.1.1