[R] pnorm how to decide lower-tail true or false

Martin Maechler maechler at stat.math.ethz.ch
Sat Jun 9 15:05:20 CEST 2007


>>>>> "CM" == Carmen Meier <carmei3 at web.de>
>>>>>     on Fri, 08 Jun 2007 19:31:49 +0200 writes:

    CM> Hi to all, maybe the last question was not clear enough.
    CM> I did not found any hints how to decide whether it
    CM> should use lower.tail or not.  As it is an extra
    CM> R-feature ( written in
    CM> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/66250.html
    CM> ) I do not find anything about it in any statistical
    CM> books of me.

Yes, most "statistical books" do not consider numerical accuracy
which is the real issue here.
Note that R is much more than a "statistical package" and hence
to be appreciated properly needs much broader (applied)
mathematical, statistical and computer science knowledge ;-)

When  p ~= 1,  '1 - p' suffers from so called cancellation
("Numerical analysis 101").
If you already know that you will use "q := 1 - p",
rather compuate 'q' directly than first compute p, then 1-p,
losing all accuracy.

All of R's  p<foo>(..) functions have an argument 'lower.tail'
which is TRUE by default, since after all,

      p<foo>(x) = Prob_{<foo>}[X <= x]   

measures the probability of the lower or left tail of the
<foo>-distribution.
<foo> = norm  is just a special case.
If you really want 
   q =  1 - p<foo>(x) = Prob_{<foo>}[X > x]   

then you can get this directly via
     
   q <- p<foo>(x, lower.tail = FALSE, ....)


Simple example with R :

> pnorm(10)
[1] 1
> 1 - pnorm(10)
[1] 0
> pnorm(10, lower.tail=FALSE)
[1] 7.619853e-24


Regards,
Martin Maechler, ETH Zurich



More information about the R-help mailing list