[R] evaluating density objects

Daniel E. Ho deho at fas.harvard.edu
Fri Nov 15 18:54:19 CET 2002


Another way to do get multiple density estimates in the same plot:

dens1 <- density(VAR1)
dens0 <- density(VAR2)
plot(dens1$x,dens1$y,type="n",xlim=c(min(c(dens1$x,dens0$x)),max(c(dens1$x,d
ens0$x))),ylim=c(min(c(dens1$y,dens0$y)),max(c(dens1$y,dens0$y))))
lines(dens1)
lines(dens0)

where dens0, dens1 represent kernel densities of your VAR1 and VAR2,
respectively, and the third line simply sets the axes to the max and min
values of the densities.

Best,

Dan

----- Original Message -----
From: "Liaw, Andy" <andy_liaw at merck.com>
To: "'Hinnerk Boriss'" <boriss at izbi.uni-leipzig.de>; <ripley at stats.ox.ac.uk>
Cc: <R-help at stat.math.ethz.ch>
Sent: Friday, November 15, 2002 11:46 AM
Subject: RE: [R] evaluating density objects


> Are you talking about overlaying all the density estimates in the same
plot?
> If you have the density estimates in a matrix, just use something like:
>
> matplot(X, density.X, type="l")
>
> where X is the vector of points where density is estimated (e.g., the x
> component of a density object) and density.X is the matrix containing the
> density estimates.  Check out the options to matplot in its help page.
>
> HTH,
> Andy
>
>
> -----Original Message-----
> From: Hinnerk Boriss [mailto:boriss at izbi.uni-leipzig.de]
> Sent: Friday, November 15, 2002 10:57 AM
> To: ripley at stats.ox.ac.uk
> Cc: R-help at stat.math.ethz.ch
> Subject: RE: [R] evaluating density objects
>
>
> Thanks for all the suggestions!
>
> > dens <- density(...)
> > write.table(data.frame(x=dens$x, y=dens$y), "somefile")
> >
> > I have no idea why anyone would want to plot in gnuplot
> > rather than in R,
> > and hence don't know what formats gnuplot accepts.
>
> The point is that I want to plot many densities in one graph. I can do
> that with R using par(new=T), but I cannot print those graphs.
>
> Thus, I wonder if I could also apply (lapply) density(...) to a vector
> of x-values, to get a my different density functions evaluated all at
> the same x. Then, I should be able to write a file that looks like:
>
> X dens1(X) dens2(X) ...
>
> Can anyone help?
>
> Cheers,
> Hinnerk
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.
> -.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._
>
> --------------------------------------------------------------------------
----
> Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (Whitehouse Station, New Jersey, USA) that
may be confidential, proprietary copyrighted and/or legally privileged, and
is intended solely for the use of the individual or entity named on this
message.  If you are not the intended recipient, and have received this
message in error, please immediately return this by e-mail and then delete
it.
>
>
============================================================================
==
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list