Here:
https://www.python-graph-gallery.com/74-density-plot-of-several-variables
Python's seaborn library is used to illustrate how to plot multiple kernel density estimates (KDEs) on the same set of axes using the famous iris dataset. However, it seems to ignore the fact that the plots should be computed using the same bandwidth.
I have two datasets that I need to plot in R using density(), but believe I should ensure the curves have the same bandwidth.
Is it necessary to ensure this? That is, what are the statistical consequences of not ensuring this? Could someone illustrate with an example?
x<-rnorm(10^3);plot(density(x,bw=0.234))though whether this is better than two different default automatic bandwidths is another question – Henry Nov 23 '22 at 15:58bw=0.234may not be the optimal choice. – compbiostats Nov 23 '22 at 16:03d1=density(x1); d1$bwand the same for the second set. You could then take the average, the minimum, or maximum of the two bandwidths and then rundensityon both data sets. – JimB Nov 23 '22 at 18:32Rcode to specify the bandwidth. The code at https://stats.stackexchange.com/a/438972/919 deals with the same problem of using the same bandwidth to compare KDEs. – whuber Nov 23 '22 at 18:57