[R] Help interpreting density().

rkevinburton at charter.net
Tue, 29 Jul 2008 04:14:46 -0000

I issue the following:

> d <- density(rnorm(1000))
> d

and get:

Call:
        density.default(x = rnorm(1000))

Data: rnorm(1000) (1000 obs.);  Bandwidth 'bw' = 0.2235

       x                 y
 Min.   :-3.5157   Min.   :2.416e-05
 1st Qu.:-1.6892   1st Qu.:1.129e-02
 Median : 0.1373   Median :7.267e-02
 Mean   : 0.1373   Mean   :1.367e-01
 3rd Qu.: 1.9639   3rd Qu.:2.693e-01
 Max.   : 3.7904   Max.   :4.014e-01

The documentation indicates that the bw is essentially the sd. Yet I have
specified an sd of 1? How am I to interpret the ranges of the values? x ranges
almost from -4 to +4 and y ranges from 0 to 0.4. The mean x is .1 which
isn't too awfully close to what I would expect (0.0). Then there is:

> d <- density(rpois(1000,0))
> d

Call:
        density.default(x = rpois(1000, 0))

Data: rpois(1000, 0) (1000 obs.);       Bandwidth 'bw' = 0.2261

       x                 y
 Min.   :-0.6782   Min.   :0.01979
 1st Qu.:-0.3391   1st Qu.:0.14073
 Median : 0.0000   Median :0.57178
 Mean   : 0.0000   Mean   :0.73454
 3rd Qu.: 0.3391   3rd Qu.:1.32830
 Max.   : 0.6782   Max.   :1.76436

Here I am getting the mean that I expect from a Poisson distribuition but y
ranges from 0 to 1.75. Again I am not sure what these numbers mean. How can I
map the output to the standard distirbution description parameters?

Thank you.

Kevin