[R] intersection of 2 density curves

Monica Pisica pisicandru at hotmail.com
Thu Oct 8 17:25:54 CEST 2009


 <57D3C6E9-402B-4991-A53B-71E25AF789F8 at comcast.net>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


No worries there =3B-)) But thanks for the reminder all the same!
=20
Monica

----------------------------------------
> CC: pisicandru at hotmail.com=3B r-help at stat.math.ethz.ch
> From: dwinsemius at comcast.net
> To: r.m.krug at gmail.com
> Subject: Re: [R] intersection of 2 density curves
> Date: Thu=2C 8 Oct 2009 11:16:22 -0400
>
> It should also be remembered that there will often be multiple
> intersections of such density estimates.
>
> I hope this is not being done in support of a data-driven
> discretization of two group comparisons. Such practices are to be
> eschewed (as they are even worse than obfuscation).
>
> --
> David Winsemius.
>
>
> On Oct 8=2C 2009=2C at 10:01 AM=2C Rainer M Krug wrote:
>
>> On Thu=2C Oct 8=2C 2009 at 3:48 PM=2C Monica Pisica
>> wrote:
>>
>>>
>>>
>>> Hi=2C
>>>
>>> I would like to find out the coordinates of the intersection points
>>> of 2
>>> density curves. I did a search but i didn't get any significant
>>> results. I
>>> really hope some of you have some ideas. here it is an example:
>>>
>>> set.seed(123)
>>> x1 <- rnorm(100=2C 1=2C 1)
>>> x2 <- rnorm(100=2C 0=2C 1)
>>> d1 <- density(x1)
>>> d2 <- density(x2)
>>>
>>> plot(d1=2C col =3D 2)
>>> lines(d2=2C col =3D 4)
>>>
>>>
>> if you specify n=2C from ant to in density() and keep them the same=2C
>> then the
>> density estimates are done for the same x-coordinates. Therefore you
>> can
>> compare d1$y with d2$y to deternine=2C where they intersect:
>>
>> d2 <- density(x2=2C from=3D-3=2C to=3D5=2C n=3D2048)
>> d1 <- density(x1=2C from=3D-3=2C to=3D5=2C n=3D2048)
>> plot(d1=2C col =3D 2)
>> lines(d2=2C col =3D 4)
>> d1$y < d2$y
>> intersX <- d1$x[as.logical(abs(diff(d1$y < d2$y)))]
>> intersY <- d1$y[as.logical(abs(diff(d1$y < d2$y)))]
>> abline(v=3Dinters)
>> abline(h=3DintersY)
>>
>> Cheers=2C
>>
>> Rainer
>>
>>
>>> Now i would like to know the coordinates of the intersection point.
>>> I did
>>> some "trial and error" and i come up with these .... (that means i
>>> did
>>> several vertical and horizontal lines through the graph until
>>> visually i
>>> "hit" the intersection point)
>>>
>>> abline(v =3D 0.35=2C lty =3D 2)
>>> abline(h =3D 0.34=2C lty =3D 2)
>>>
>>> I really appreciate any hints you may have=2C thanks so much=2C
>>>
>>> Monica
>>> _________________________________________________________________

>>> http://clk.atdmt.com/GBL/go/171222985/direct/01/
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented=2C minimal=2C self-contained=2C reproducible code=
.
>>>
>>
>>
>>
>> --
>> Rainer M. Krug=2C PhD (Conservation Ecology=2C SUN)=2C MSc (Conservation
>> Biology=2C
>> UCT)=2C Dipl. Phys. (Germany)
>>
>> Centre of Excellence for Invasion Biology
>> Natural Sciences Building
>> Office Suite 2039
>> Stellenbosch University
>> Main Campus=2C Merriman Avenue
>> Stellenbosch
>> South Africa
>>
>> Cell: +27 - (0)83 9479 042
>> Fax: +27 - (0)86 516 2782
>> Fax: +49 - (0)721 151 334 888
>> email: Rainer at krugs.de
>>
>> Skype: RMkrug
>> Google: R.M.Krug at gmail.com
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.=
html
>> and provide commented=2C minimal=2C self-contained=2C reproducible code.
>
> David Winsemius=2C MD
> Heritage Laboratories
> West Hartford=2C CT
> 		 	   		  =0A=
_________________________________________________________________=0A=
Hotmail: Powerful Free email with security by Microsoft.=0A=




More information about the R-help mailing list