[R] Question on density values obtained from kde2d() from package MASS
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Nov 24 19:25:22 CET 2011
On Thu, 24 Nov 2011, Andreas Klein wrote:
> Hello,
>
> I am a little bit confused regarding the density values obtained
> from the function kde2d() from the package MASS because the are not
> in the intervall [0,1] as I would expect them to be. Here is an
Your expectation is wrong.
> example:
>
> x <- c(0.0036,0.0088,0.0042,0.0022,-0.0013,0.0007,0.0028,-0.0028,0.0019,0.0026,-0.0029,-0.0081,-0.0024,0.0090,0.0088,0.0038,0.0022,0.0068,0.0089,-0.0015,-0.0062,0.0066)
> y <- c(0.00614,0.00194,0.00264,0.00064,0.00344,0.00314,-0.00006,-0.00066,0.00174,0.00274,-0.00076,0.00024,-0.00236,0.00234,0.00504,0.00114,0.00054,-0.00116,-0.00016,-0.00566,0.00044,0.00404)
>
> tmp <- kde2d(x=x, y=y, n=100)
> range(tmp$z)
> #3.621288 11989.060924
>
> Do I have to transform them further? Or what scale are they?
They are density values, as you quote from the help page. Try
dnorm(0, 0, 1e-6) in R. That's a density, way above 1.
Perhaps you need to revise Probability 101.
> Or did I get something wrong regarding the output because in the help file it reads:
> "zAn n[1] by n[2] matrix of the estimated density: rows
^^^^^^^^^^^^^^^^^
> correspond to the value of x, columns to the value of y."
>
>
> Regards,
> Andy.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list