Skip to content

Numerical precision problem

4 messages · C.Rosa at lse.ac.uk, Duncan Murdoch, Thomas Lumley +1 more

#
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?
[1] FALSE
[1] TRUE

Interestingly,
[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:
No, the limitations are inherent in the floating point representation 
that R uses.
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
#
On Fri, 21 Dec 2007, C.Rosa at lse.ac.uk wrote:

            
No, since q is not different from 1.
Use the lower.tail= argument to qnorm (or just use the fact that the 
standard Normal is symmetric)
[1] 1e-32
[1] 11.85613
[1] 11.85613
-thomas
#
C.Rosa at lse.ac.uk wrote:
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.