Dear All, I have a numerical problem: R, as other statistical software, can tell the difference between very small numbers and 0, while apparently cannot distinguish a number close to 1 and 1. In the example below, is it possible to instruct R to recognize that q is different from 1?> p=.00000000000000000000000000000001> p==0[1] FALSE> q=.99999999999999999999999999999> q==1[1] TRUE Interestingly,> (1-p)==1[1] TRUE The main problem I have is that I need to evaluate the inverse of the normal Cumulative Distribution Function near 1 (but not exactly 1) and the PC cannot recognize it. Thank you very much for your help! Carlo Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
On 21/12/2007 2:52 PM, C.Rosa at lse.ac.uk wrote:> Dear All, > > > > I have a numerical problem: > > R, as other statistical software, can tell the difference between very small numbers and 0, while apparently cannot distinguish a number close to 1 and 1. In the example below, is it possible to instruct R to recognize that q is different from 1?No, the limitations are inherent in the floating point representation that R uses.>> p=.00000000000000000000000000000001 > >> p==0 > > [1] FALSE > >> q=.99999999999999999999999999999 > >> q==1 > > [1] TRUE > > Interestingly, > >> (1-p)==1 > > [1] TRUE > > The main problem I have is that I need to evaluate the inverse of the normal Cumulative Distribution Function near 1 (but not exactly 1) and the PC cannot recognize it.In this particular case, it's easy: make use of the symmetry of the distribution. If you want the 1-epsilon quantile of a normal with mean mu, find the epsilon quantile, and reflect it through mu: mu <- 3 -qnorm(1e-30, mean=-mu) More generally, you can make use of the log.p argument to the quantile functions, and the fact that log(1-epsilon) is close to -epsilon: qnorm(-1e-30, mean=mu, log.p=TRUE) Duncan Murdoch> > Thank you very much for your help! > > Carlo > > > Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm > > ______________________________________________ > R-help at r-project.org 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.
On Fri, 21 Dec 2007, C.Rosa at lse.ac.uk wrote:> Dear All, > > > > I have a numerical problem: > > R, as other statistical software, can tell the difference between very > small numbers and 0, while apparently cannot distinguish a number close > to 1 and 1. In the example below, is it possible to instruct R to > recognize that q is different from 1?No, since q is not different from 1.> >> q==1 > > [1] TRUE >> > The main problem I have is that I need to evaluate the inverse of the > normal Cumulative Distribution Function near 1 (but not exactly 1) and > the PC cannot recognize it. >Use the lower.tail= argument to qnorm (or just use the fact that the standard Normal is symmetric)> p=.00000000000000000000000000000001 > p[1] 1e-32> qnorm(p,lower.tail=FALSE)[1] 11.85613> -qnorm(p)[1] 11.85613>-thomas
C.Rosa at lse.ac.uk wrote:> Dear All, > ....>> (1-p)==1 > > [1] TRUE > > The main problem I have is that I need to evaluate the inverse of the normal Cumulative Distribution Function near 1 (but not exactly 1) and the PC cannot recognize it.Evaluate it at 1, evaluate the density at 1, and use basic calculus to calculate the differential of the cumulative distribution for small differentials away from 1.
Maybe Matching Threads
- Getting high precision values from qnorm in the tail
- Is there a way to handle window (FXDialogBox) "close event" (or any other event/message)?
- FXColorDialog slow UI update
- Loop with string variable AND customizable "summary" output
- spaghetti plot - urgent