StoreyLab / qvalue

R package to estimate q-values and false discovery rate quantities.
109 stars 36 forks source link

Code fails if tabulate produces NA values #36

Closed nskot closed 1 year ago

nskot commented 1 year ago

https://github.com/StoreyLab/qvalue/blob/9b3f9a8af4dc8b680a6914d1fcc106e041b7c7a0/R/pi0est.R#L111

This will fail if some intervals don't contain any p-values, for example if the largest p-value is 0.93 the first entry will be NA and then the whole cumsum will be NA, it can be fixed with:

    freqs <- tabulate(findInterval(p, vec = lambda))[ind]
    freqs <– ifelse(is.na(freqs), 0, freqs)
    pi0 <- cumsum(freqs)/(length(p) * (1 - lambda[ind]))
jdstorey commented 1 year ago

32

nskot commented 1 year ago

How is this completed? We sometimes have tens of thousands of p-values not covering all intervals. Either way, the code shouldn’t produce NAs here in the first place