Thanks David and Stephan,

David's reply was very helpful since I now realize how I made in my head the
(wrong) assumption that the hist would automatically produce rectangular
bars with the width of 1 (since the distribution is a discrete one).
The call:
hist(x)$breaks
Helped to bring me back to focus.

Stephan, I remember studying about "Riemann integral" but didn't remember
that's how it is called - thanks for the link.



Tal


----------------Contact
Details:-------------------------------------------------------
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Sat, Mar 13, 2010 at 11:04 PM, Stephan Kolassa <stephan.kola...@gmx.de>wrote:

> Hi Tal,
>
> basically, by summing over the (pointwise) density, you are "approximating"
> the integral over the density (which should be around 1) - but to really do
> a rectangular approximation, you will of course need to multiply each
> function value by the width of the corresponding rectangle. I'd recommend
> reading through Wikipedia's article on the Riemann integral, you may be
> enlightened.
> http://en.wikipedia.org/wiki/Riemann_integral
>
> HTH,
> Stephan
>
>
> Tal Galili schrieb:
>
>> Hi all,
>>
>> A friend send me a question on why does this:
>>
>> x<-rpois(100,1)
>> sum( hist(x)$density )
>>
>> Gives out "2"
>>
>> I tried this:
>>
>> sum( hist(x, freq =T)$density )
>>
>> It didn't help.
>>
>> Then he came back with the following insight:
>>
>> # with breaks
>> b<-c(0,0.9,1:8)
>> sum(hist(x,breaks=b)$density) # Much more then 2
>> # but if we add weights according to the interval length
>> sum(hist(x,breaks=b)$density * diff(b))
>> # it works
>>
>>
>>
>> What do you think ?
>>
>>
>> Tal
>>
>>
>>
>> ----------------Contact
>> Details:-------------------------------------------------------
>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>
>> ----------------------------------------------------------------------------------------------
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@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.
>>
>>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to