Skip to content
Prev 278324 / 398513 Next

How to increase precision to handle very low P-values

On 23/11/2011 11:16 AM, alonso_canada wrote:
The p* functions (pnorm, etc.) generally have a "log" argument, so they 
can return logs of probabilities.  Together with the "lower" argument, 
they have a huge range.

To use them with integrate(), rescale them.  For example, to find the 
integral of pnorm() from z=-32 to -30 you could do:

maxval <- pnorm(-30, log=TRUE)
scaled <- function(x) exp( pnorm(x, log=TRUE) - maxval )
scaledintegral <- integrate(scaled, lower=-32, upper=-30)
# Log of the result:
log(scaledintegral$value) + maxval

(The answer is -457.7, so it is actually representable:  1.631957e-199.)

Duncan Murdoch