# [R] density > 1?

Bernardo Rangel Tura tura at centroin.com.br
Mon Mar 2 23:53:47 CET 2009

```On Mon, 2009-03-02 at 13:27 +0100, Johannes Elias wrote:
> Dear R-Gurus,
>
> I wonder why 'density' values as shown in hist or plot(density(x)) are
> sometimes over 1. How can that be?
>
> Example
>
> >hist(rnorm(1000,sd=.5),freq=FALSE)
>
> The resulting plot shows density values below 1 on the y-axis. However,
>
> >hist(rnorm(1000,sd=.1),freq=FALSE)
>
> shows density values over 1.
>
> How to interpret density values over 1?
>
> Greetings,
>
> Johannes

Johannes,

Well density is not like probability

In histogram with density the area is equal de probability

in you example

set.seed(123)
hist(rnorm(1000,sd=.1),freq=FALSE)

The interval of -0.05 and 0 have density=4 but a probability of number
in this interval is 4*.05=.2

the fact

set.seed(123)
hist(rnorm(1000,sd=.1),freq=FALSE)\$density
[1] 0.09999998 0.28000000 0.94000000 1.98000000 2.60000000 4.00000000
[7] 4.04000000 2.92000000 1.66000000 0.92000000 0.44000000 0.10000000
[13] 0.02000000

set.seed(123)
sum(hist(rnorm(1000,sd=.1),freq=FALSE)\$density)
[1] 1

So the sum of probability is 1 but the sum of density 20

--
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil

```

More information about the R-help mailing list