Skip to content

Negatives density values (PR#8876)

2 messages · Cuvelier Etienne, Duncan Murdoch

#
Full_Name: Cuvelier Etienne
Version: R version 2.2.1
OS: Windows XP
Submission from: (NULL) (81.240.71.204)


If we use the "density" function "far" from the data, some values are
negatives.
I know that these value of the density are "near equal" to zero, but the change
of sign can involve some "false" decision.

Here is an example of this fact:
+ 0.048, 0.044, 0.168)
[1] 0.002
[1] 0.168
[1]  2.433854e-17  1.726562e-17  1.285227e-16  2.359248e-16
 [5]  4.628709e-17 -1.535879e-16  1.438105e-16  2.023210e-16
 [9]  2.649354e-11  1.438340e-01  7.679909e+00  1.767860e+00
[13]  2.056151e-04 -1.407219e-16 -3.575895e-18 -1.979607e-16
[17] -1.574544e-17 -2.257917e-17 -2.305234e-16  4.052727e-18
[1] TRUE
R version 2.2.1, 2005-12-20, i386-pc-mingw32

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"
[6] "datasets"  "base"
sysname                       release 
                    "Windows"                      "NT 5.1" 
                      version                      nodename 
"(build 2600) Service Pack 2"                       "WINXP" 
                      machine                         login 
                        "x86"                     "Etienne" 
                         user 
                    "Etienne"
$platform
[1] "i386-pc-mingw32"

$arch
[1] "i386"

$os
[1] "mingw32"

$system
[1] "i386, mingw32"

$status
[1] ""

$major
[1] "2"

$minor
[1] "2.1"

$year
[1] "2005"

$month
[1] "12"

$day
[1] "20"

$"svn rev"
[1] "36812"

$language
[1] "R"
2 days later
#
On 5/18/2006 10:51 AM, ecu at info.fundp.ac.be wrote:
I wouldn't consider this a bug, rather a consequence of using the 
Fourier transform to do the density estimate, as documented.

If slightly negative values of the density cause trouble for you, then 
use pmax(density, 0) to force them to be non-negative, or use a 
different algorithm for the estimates.

Duncan Murdoch