> x <- rnorm(1000) > h <- hist(x,plot=FALSE) > sum(h$density)[1] 2 ----------------------------- shouldn't it be 1?!> h <- hist(x,plot=FALSE, breaks=(-4:4)) > sum(h$density)[1] 1 ----------------------------- now it's 1. why?! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000 http://www.childpsy.net/ http://www.memritv.org http://openvotingconsortium.org http://thereligionofpeace.com http://mideasttruth.com http://palestinefacts.org ((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))
Hi Sam, ?hist gives: "density ? ??values f^(x[i]), as estimated density values. If all(diff(breaks) == 1), they are the relative frequencies counts/n and in general satisfy sum[i; f^(x[i]) (b[i+1]-b[i])] = 1, where b[i] = breaks[i]." 1st case, ?density != frequency because?all(diff(breaks) == 1) is FALSE (diff = 0.5); sum(h$density*diff) = 1 2nd case, density == frequency?because all(diff(breaks) == 1) is TRUE (diff = 1); sum(h$density*diff) = 1 Regards, Pascal -- Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X 11.0.11004000 http://www.childpsy.net/ http://www.memritv.org http://openvotingconsortium.org http://thereligionofpeace.com http://mideasttruth.com http://palestinefacts.org ((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x))) ______________________________________________ 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, minimal, self-contained, reproducible code.
Your clue is... density!
Probability density is not the same as probability... you have to multiply it by
something before you can sum it.
Try typing
h
by itself and review your options.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Sam Steingold <sds at gnu.org> wrote:
>> x <- rnorm(1000)
>> h <- hist(x,plot=FALSE)
>> sum(h$density)
>[1] 2 ----------------------------- shouldn't it be 1?!
>
>> h <- hist(x,plot=FALSE, breaks=(-4:4))
>> sum(h$density)
>[1] 1 ----------------------------- now it's 1. why?!
>
>
>
>--
>Sam Steingold (http://sds.podval.org/) on Ubuntu 11.10 (oneiric) X
>11.0.11004000
>http://www.childpsy.net/ http://www.memritv.org
>http://openvotingconsortium.org
>http://thereligionofpeace.com http://mideasttruth.com
>http://palestinefacts.org
>((lambda (x) `(,x ',x)) '(lambda (x) `(,x ',x)))
>
>______________________________________________
>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, minimal, self-contained, reproducible code.