[R] How is the relation between Frequency and Counts in hist/density defined?

jim holtman jholtman at gmail.com
Mon May 23 17:41:55 CEST 2011


try this -- it scales to the maximum value:

set.seed(242)
z = rnorm(30)
hist_z <- hist(z)
hist_z$counts / hist_z$density # the relation is 15
# why is this 15 ??
# So I can now do:
hist(z)
# change in this statement - scale to the max
y <- density(z)$y  * max(hist_z$counts) / max(density(z)$y)
#is what I hope to find without using hist, and only using density
x <- density(z)$x
lines(x = x, y = y, col = "blue", lwd = 5)



On Mon, May 23, 2011 at 10:56 AM,  <Richard.Cotton at hsl.gov.uk> wrote:
>
>   > In order to do this I can use the relation between count and density, but
>   I
>   > would like to know if there is a way for me to predict it upfront.
>   In the code for hist.default, you'll see the line
>   dens <- counts/(n * diff(breaks))
>   > Here is an example:
>   >
>   > set.seed(242)
>   > z = rnorm(30)
>   > hist_z <- hist(z)
>   > hist_z$counts / hist_z$density # the relation is 15
>   In your example, n is 30, and the breaks are evenly spaced every 0.5.
>   Regards,
>   Richie.
>   Mathematical Sciences Unit
>   [1]HSL
>   [2]4D Pie Charts
>     _________________________________________________________________
>
>   ATTENTION:
>
>
>
>   This message contains privileged and confidential information intended for
>   the addressee(s) only. If this message was sent to you in error, you must
>   not disseminate, copy or take any action in reliance on it and we request
>   that you notify the sender immediately by return email.
>
>
>
>   Opinions expressed in this message and any attachments are not necessarily
>   those held by the [3]Health and Safety Laboratory or any person connected
>   with the organisation, save those by whom the opinions were expressed.
>
>
>
>   Please note that any messages sent or received by the [4]Health and Safety
>   Laboratory  email system may be monitored and stored in an information
>   retrieval system.
>     _________________________________________________________________
>
>   Think before you print - do you really need to print this email?
>     _________________________________________________________________
>     _________________________________________________________________
>
>   Scanned by MailMarshal - Marshal's comprehensive email content security
>   solution. Download a free evaluation of MailMarshal at [5]www.marshal.com
>     _________________________________________________________________
>
> References
>
>   1. http://www.hsl.gov.uk/contact-us.htm
>   2. http://4dpiecharts.com/
>   3. http://www.hsl.gov.uk/
>   4. http://www.hsl.gov.uk/
>   5. http://www.marshal.com/
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list