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

2007-06-09 Thread Martin Maechler
> "CM" == Carmen Meier <[EMAIL PROTECTED]>
> 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(..) functions have an argument 'lower.tail'
which is TRUE by default, since after all,

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

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

then you can get this directly via
 
   q <- p(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

__
[email protected] 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.


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

2007-06-08 Thread Robert A LaBudde
At 01:31 PM 6/8/2007, Carmen wrote:
>Hi to all,
>maybe the last question was not clear enough.
>I did not found any hints how to decide whether it should use lower.tail
>or not.
>As it is an extra R-feature ( written in
>http://finzi.psych.upenn.edu/R/Rhelp02a/archive/66250.html )
>I do not find anything about it in any statistical books of me.
>Regards Carmen

pnorm(z, lower.tail=TRUE) (the R default) gives the probability of a 
normal variate being at or below z. This is the value commonly called 
the cumulative distribution function at the point z, or the integral 
from -Inf to z of the gaussian density.

pnorm(z, lower.tail=FALSE) gives the complement of the above, or 1 - 
cdf(z), and is the integral from z to Inf of the gaussian density.

E.g.,

 > pnorm(1.96, lower.tail=TRUE)
[1] 0.9750021
 > pnorm(1.96, lower.tail=FALSE)
[1] 0.02499790
 >

Use lower.tail=TRUE if you are, e.g., finding the probability at the 
lower tail of a confidence interval or if you want to the probability 
of values no larger than z.

Use lower.tail=FALSE if you are, e.g., trying to calculate test value 
significance or at the upper confidence limit, or you want the 
probability of values z or larger.

You should use pnorm(z, lower.tail=FALSE) instead of 1-pnorm(z) 
because the former returns a more accurate answer for large z.

This is really simple issue, and has no inherent complexity 
associated with it.

Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: [EMAIL PROTECTED]
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

"Vere scire est per causas scire"

__
[email protected] 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.


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

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

__
[email protected] 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.