[R] workaround for numeric problems

From: Ott Toomet <otoomet_at_ut.ee>
Date: Sun 02 Jul 2006 - 20:00:10 EST


Dear R-people,

I have to compute

C - -(pnorm(B)*dnorm(B)*B + dnorm(B)^2)/pnorm(B)^2

This expression seems to be converging to -1 if B approaches to -Inf (although I am unable to prove it). R has no problems until B equals around -28 or less, where both numerator and denominator go to 0 and you get NaN. A simple workaround I did was

C <- ifelse(B > -25,

           -(pnorm(B)*dnorm(B)*B + dnorm(B)^2)/pnorm(B)^2,
            -1)

It works well for me (32bit intel/linux platform). But what about other processors/platforms/compilator options? Are there any better ways for finding out at which values the numerical problems start? Can one derive something from .Machine$double.eps (but what about the precison of dnorm and other analytic functions)?

Thanks in advance,
Ott



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jul 02 20:12:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 02 Jul 2006 - 22:15:15 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.