[R] density of hist(freq = FALSE) inversely affected by data magnitude

J Toll jctoll at gmail.com
Wed Jan 23 02:32:03 CET 2013


Bill,

Thank you.  I got it.  That can require a fair amount of work to
interpret the density, especially with odd or irregular bin sizes.

Thanks again,

James



On Tue, Jan 22, 2013 at 5:33 PM, William Dunlap <wdunlap at tibco.com> wrote:
> The probability density function is not unitless - it is the derivative of the
> [cumulative] probability distribution function so it has units delta-probability-mass
> over delta-x.  It must integrate to 1 (over the all possible x).  hist(freq=FALSE,x)
> or hist(prob=TRUE,x) displays an estimate of the density function and the following
> example shows how the scale matches what you get from the presumed
> population density function.
>
>> f
> function (n, sd)
> {
>     x <- rnorm(n, sd = sd)
>     hist(x, freq = FALSE) # estimated density
>     s <- seq(min(x), max(x), len = 129)
>     lines(s, dnorm(s, sd = sd), col = "red") # overlay expected density for this sample
> }
>> f(1e6, sd=1)
>> f(100, sd=1)
>> f(100, sd=0.0001)
>> f(1e6, sd=0.0001)
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com



More information about the R-help mailing list