Wednesday, August 14, 2013

Zero p-values in R

For the top hits from an R program, I was getting all zero p-values, which are not that useful for ranking or plotting.

Turns out that the R program was calculating the p-value in this manner:

1 - pchisq(71.12830,1)

But, according to the discussion here, in R

".Machine$double.eps is the smallest number such that 1+x can be distinguished from 1"

On my machine, we have that:

> .Machine$double.eps
[1] 2.220446e-16

So that is why this truncates to zero:

> 1 - pchisq(71.12830,1)
[1] 0

However, we can get a non-zero p-value if instead we compute it this way:

> pchisq(71.12830,1,lower.tail=FALSE)
[1] 3.347341e-17

About Me

My photo
Pittsburgh, PA, United States