[R] comparative density estimates

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Thu Mar 23 21:45:10 CET 2006


Michael,

very nice and interesting plots!

One alternative idea to compare the proportion of milestone items
(that does not really answer the bandwith question) in Europe and North
America might be a conditional density plot. After running your R
source code, you could do:
  where <- factor(c(rep("North America", length(sub1)),
                    rep("Europe", length(sub2)))) 
  year <- c(sub1, sub2)
  cdplot(where ~ year, bw = "sj")
showing the decrease in the European proportion.

Internally, this first computes the unconditional density as in
  plot(density(year, bw = "sj"))
and then the density for Europe with the same bandwidth.

Best wishes,
Z


On Thu, 23 Mar 2006 14:25:53 -0500 Michael Friendly wrote:

> I have two series of events over time and I want to construct a graph
> of the relative frequency/density of these events that allows their 
> distributions to
> be sensibly compared.  The events are the milestones items in my
> project on milestones in the history of data visualization [1], and I
> want to compare trends
> in Europe vs. North America.
> 
> I decided to use a graph of two overlaid density estimates with rug 
> plots, but then
> the question arises of how to choose the bandwidth (BW) for the two 
> series to allow them
> to be sensibly compared, because the range of time and total
> frequency differ
> for the two series.  To avoid clutter on this list, I've placed the
> data and R code
> at
> http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/kde-bug/mileyears4.R
> 
> I have two versions of this graph, one selecting an optimal BW for
> each separately
> and the other using the adjust= argument of density() to
> approximately equate
> the BW to the value determined for the whole series combined.  The
> two versions
> (done with SAS) are shown at
> 
> http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/kde-bug/mileyears32.gif 
> 
> http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/kde-bug/mileyears33.gif 
> 
> 
> The densities in the first are roughly equivalent to the R code
> d1 <- density(sub1, from=1500, to=1990, bw="sj", adjust=1)
> d2 <- density(sub2, from=1500, to=1990, bw="sj", adjust=1)
> 
> the second to
> d1 <- density(sub1, from=1500, to=1990, bw="sj", adjust=2.5)
> d2 <- density(sub2, from=1500, to=1990, bw="sj", adjust=0.75)
> 
> The second graph seems to me to undersmooth the more extensive data
> from Europe and undersmooth the data from North America.
> 
> - any comments or suggestions?
> - are there other methods I should consider?
> 
> I did find overlap.Density() in the DAAG package, but perversely, it 
> uses a bw=
> argument to select a B&W/grayscale plot.
> 
> thanks,
> -Michael
> 
> 
> [1] http://www.math.yorku.ca/SCS/Gallery/milestone/
> 
> -- 
> Michael Friendly     Email: friendly at yorku.ca 
> Professor, Psychology Dept.
> York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
> Toronto, ONT  M3J 1P3 CANADA
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list