nothnagel at medinfo.uni-kiel.de
2007-Jan-31 14:16 UTC
[Rd] Bug in 'pchisq' for x=0.0 (PR#9485)
The function 'pchisq' from the 'stats' library gives a wrong result if the argument equals exactly zero: # Upper tail of central 1-df chi^2 distribution> pchisq(1 , 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0.3173105> pchisq(0.5 , 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0.4795001> pchisq(0.01 , 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0.9203443> pchisq(0.0001 , 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0.9920213> pchisq(0.00000001, 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0.9999202> pchisq(0.00 , 1, ncp=0, lower.tail = F, log.p = FALSE)[1] 0 ## Should be 1.0 The error occurred with R version 2.4.0 (windows) and version 2.3.1 (linux). Best regards, Michael Nothnagel --- Dr. Michael Nothnagel Institute of Medical Informatics and Statistics, University of Kiel http://capella.uni-kiel.de/ ---
maechler at stat.math.ethz.ch
2007-Jan-31 16:38 UTC
[Rd] Bug in 'pchisq' for x=0.0 (PR#9485)
>>>>> "MN" == Michael Nothnagel <nothnagel at medinfo.uni-kiel.de> >>>>> on Wed, 31 Jan 2007 15:16:02 +0100 (CET) writes:MN> The function 'pchisq' from the 'stats' library gives a wrong result if the MN> argument equals exactly zero: MN> # Upper tail of central 1-df chi^2 distribution >> pchisq(1 , 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0.3173105 >> pchisq(0.5 , 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0.4795001 >> pchisq(0.01 , 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0.9203443 >> pchisq(0.0001 , 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0.9920213 >> pchisq(0.00000001, 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0.9999202 >> pchisq(0.00 , 1, ncp=0, lower.tail = F, log.p = FALSE) MN> [1] 0 ## Should be 1.0 MN> The error occurred with R version 2.4.0 (windows) and version 2.3.1 (linux). Yes, but both of these R versions are outdated. The current version is 2.4.1 and there, the result *is* 1. Regards, Martin Maechler, ETH Zurich
Please do not report on obsolete versions of R! From the changes from
2.4.1:
o pchisq() would sometimes use the wrong tail when calculating
non-central probabilities with lower.tail = FALSE. (PR#9406)
You are quite explicitly asked not to waste the R project's resources in
this way. Please do re-read the FAQ.
On Wed, 31 Jan 2007, nothnagel at medinfo.uni-kiel.de wrote:
> The function 'pchisq' from the 'stats' library gives a
wrong result if the
> argument equals exactly zero:
>
> # Upper tail of central 1-df chi^2 distribution
>> pchisq(1 , 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0.3173105
>> pchisq(0.5 , 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0.4795001
>> pchisq(0.01 , 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0.9203443
>> pchisq(0.0001 , 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0.9920213
>> pchisq(0.00000001, 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0.9999202
>> pchisq(0.00 , 1, ncp=0, lower.tail = F, log.p = FALSE)
> [1] 0 ## Should be 1.0
>
> The error occurred with R version 2.4.0 (windows) and version 2.3.1
(linux).
>
>
> Best regards,
>
> Michael Nothnagel
>
> ---
> Dr. Michael Nothnagel
> Institute of Medical Informatics and Statistics,
> University of Kiel
> http://capella.uni-kiel.de/
> ---
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
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