From: Rich FitzJohn <rich.fitzjohn_at_gmail.com>

Date: Thu 05 May 2005 - 09:12:55 EST

Date: Thu 05 May 2005 - 09:12:55 EST

Hi,

A "density" object's x and y values can be accessed using $x and $y (this is in ?density, under "Value:")

obj <- density(rnorm(100, 0, 1))

obj$x

obj$y

You may find it useful to force the "from" and "to" arguments to be the same for the two calls to density(), if you want to work directly from the x and y values.

x <- rnorm(100, 0, 1)

y <- rnorm(100, .2, 1)

dx <- density(x)

dy <- density(y)

## Re-do the densities so they have the same x-values:
lim <- range(dx$x, dy$x)

dx <- density(x, from=lim[1], to=lim[2])
dy <- density(y, from=lim[1], to=lim[2])

plot(dx, col="blue", ylim=range(dx$y, dy$y))
lines(dy, col="red")

polygon(dx$x, pmin(dx$y, dy$y), col="purple")

Cheers,

Rich

On 5/5/05, Grace Clinton <gcll688@yahoo.com> wrote:

> Hi there,

*>
**> I am working on a project which needs the value of the interaction area under two distributions( eatimated by kernel density estimators).
**>
**> For example:
**>
**> x<-rnorm(100,0,1)
**> y<-rnorm(100,0.2,1)
**> density(x) # This produces the summary of dependent variable and independent variable.
**>
**> How can I get the individual values of variables and reform a curve to calculate the area under curve?
**>
**> Is there a way to get aroud this and give me the solution?
**>
**> Thanks a lot.
**>
**> Grace
**>
**> ---------------------------------
**>
**> [[alternative HTML version deleted]]
**>
**> ______________________________________________
**> R-help@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
**>
*

-- Rich FitzJohn rich.fitzjohn <at> gmail.com | http://homepages.paradise.net.nz/richa183 You are in a maze of twisty little functions, all alike ______________________________________________ R-help@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.htmlReceived on Thu May 05 09:18:19 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:31:35 EST
*