chr1swallace/coloc

Error if beta and/or varbeta contain `Inf`

oborisov opened this issue · 5 comments

coloc/R/check.R

Lines 131 to 137 in a44c817

} else {
p=pnorm( -abs( d$beta/sqrt(d$varbeta) ) ) * 2
}
## minp
if(min(p) > warn.minp)
warning("minimum p value is: ",format.pval(min(p)),"\nIf this is what you expected, this is not a problem.\nIf this is not as small as you expected, please check you supplied var(beta) and not sd(beta) for the varbeta argument. If that's not the explanation, please check the 02_data vignette.")

If beta and/or varbeta contain Inf, the error is thrown at line 137

Error in if (min(p) > warn.minp) warning("minimum p value is: ", format.pval(min(p)),  : 
  missing value where TRUE/FALSE needed

To make the error easier to debug, here is a suggestion to add check before line 132 (unless it is already checked elsewhere?)

any((d$beta %in% c(-Inf, Inf)) | (d$varbeta %in% c(-Inf, Inf)))
  stop("dataset ",suffix,": ","Infinite values in beta and/or varbeta")

Reproducible example

warn.minp <- 1e-6
d <- data.frame(beta = c(1.5, 2, Inf),
                varbeta = c(0.01, 0.9, Inf))
p=pnorm( -abs( d$beta/sqrt(d$varbeta) ) ) * 2
if(min(p) > warn.minp)
  warning("minimum p value is: ",format.pval(min(p)),"\nIf this is what you expected, this is not a problem.\nIf this is not as small as you expected, please check you supplied var(beta) and not sd(beta) for the varbeta argument. If that's not the explanation, please check the 02_data vignette.")

(Actual Inf values were found in GTExV8 raw eQTL summary statistics)

Best,
Oleg

Yes, the error happened when input vectors "beta" and "se" contained Inf.

I agree, the point was only to add an error message which may help to debug (someone running into the same issue will see that the input dataset contains Inf which cannot be used by coloc anyway, therefore these Inf need to be removed prior to running coloc).