[R] density() returns a density function that does not add up to 1
A.J. Rossini
rossini at blindglobe.net
Fri Aug 30 22:09:03 CEST 2002
>>>>> "jonathan" == Jonathan Li <jonqli at labs.agilent.com> writes:
jonathan> Dear R users,
jonathan> I ran into this curious problem:
>> d <- rnorm(100)
>> d.density <- density(d)
>> sum( d.density$x * d.density$y)
jonathan> [1] 2.517502
whoops, you probably want something like:
> sum( diff(d.density$x) * d.density$y)
[1] 1.000950
instead, for a crude integration (and yes, it throws a warning).
--
A.J. Rossini Rsrch. Asst. Prof. of Biostatistics
U. of Washington Biostatistics rossini at u.washington.edu
FHCRC/SCHARP/HIV Vaccine Trials Net rossini at scharp.org
-------------- http://software.biostat.washington.edu/ ----------------
FHCRC: M: 206-667-7025 (fax=4812)|Voicemail is pretty sketchy/use Email
UW: Th: 206-543-1044 (fax=3286)|Change last 4 digits of phone to FAX
(my tuesday/wednesday/friday locations are completely unpredictable.)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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