[R] function density (stats): parameter n

Paulo Barata pbarata at infolink.com.br
Sun May 16 17:29:32 CEST 2010


Dear R-list members,

About the parameter n of the function density() (Kernel Density
Estimation, package stats):

The R HTML documentation says about the parameter n: "the number
of equally spaced points at which the density is to be estimated.
When n > 512, it is rounded up to the next power of 2 for
efficiency reasons".
Note: 512 is the default size for n.

The code below:

data <- rnorm(500)
d <- density(data,n=800)
length(d$x)

produces this result:
[1] 800

Here, according to the R HTML documentation, d$x gives "the n
coordinates of the points where the density is estimated".

Of course, given that n=800, the next power of 2 would be 1024.

With regard to the parameter n, does the R documentation match
what function density() actually does?

I am using R 2.11.0 running on Windows XP.

Thank you very much.

Paulo Barata

------------------------------------------------------------------
Paulo Barata
Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation
Rua Leopoldo Bulhoes 1480 - 8A
21041-210  Rio de Janeiro - RJ
Brazil

E-mail: pbarata at infolink.com.br
Alternative e-mail: paulo.barata at ensp.fiocruz.br



More information about the R-help mailing list