Andreas Klein
2011-Nov-24 18:12 UTC
[R] Question on density values obtained from kde2d() from package MASS
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 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? 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.
Prof Brian Ripley
2011-Nov-24 18:25 UTC
[R] Question on density values obtained from kde2d() from package MASS
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 anYour 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
Peter Löwenberg
2014-Jan-23 19:04 UTC
[R] Question on density values obtained from kde2d() from package MASS
Hello Andy, Do you already understand kde2d output? if I run> max(tmp$z)do I take the maximum value of the 2d density? Cheers, Peter Em quinta-feira, 24 de novembro de 2011 16h12min19s UTC-2, Andreas Klein escreveu:> > 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 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? > 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. > > > ______________________________________________ > R-h... at r-project.org <javascript:> mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >