Search code examples
rprecisionp-valuegenetics

Z-scores rounded to infinity for small p-values in R


I am working with a genome-wide association study dataset, with p-values ranging from 1E-30 to 1. I have an R data frame "data" which includes a variable "p" for the p-values.

I need to perform genomic correction of the p-values, which I am doing using the following code:

    p=data$p

    Zsq = qchisq(1-p, 1)

    lambda = median(Zsq)/0.456

    newZsq = Zsq/lambda

    Newp = 1-pchisq(newZsq, 1)

In the command on the second line, where I use the qchisq function to convert p-values to z-scores, z-scores for p-values < 1E-16 are being rounded to infinity. This means the p-values for my most significant data points are rounded to 0 after the genomic correction, and I lose their ranking.

Is there any way around this?


Solution

  • Read help(".Machine"). Then set lower.tail=FALSE and avoid taking differences with 1:

    p <- 1e-17
    
    Zsq = qchisq(p, 1, lower.tail=FALSE)
    
    lambda = median(Zsq)/0.456
    
    newZsq = Zsq/lambda
    
    Newp = pchisq(newZsq, 1, lower.tail=FALSE)
    #[1] 0.4994993