StoreyLab / qvalue

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

Error in smooth.spline(lambda, pi0, df = smooth.df) : #20

Closed montenegrina closed 1 year ago

montenegrina commented 4 years ago

Hello,

I am getting this error when I run:

pvals=d$META qval_obj=qvalue(pvals) Error in smooth.spline(lambda, pi0, df = smooth.df) : missing or infinite values in inputs are not allowed length(pvals) [1] 28206 sum(is.na(d$META)) [1] 0

I would say that I have enough of p values and there is no NAs. Can you please advise what to do about this?

Thanks Ana

montenegrina commented 4 years ago

can someone please get back to me about this?

andremrsantos commented 3 years ago

When I was testing, I found a similar issue. You can replicate it with the following code:

> set.seed(1);  qvalue(rbeta(10, .5, .5))$qvalues
# Error in smooth.spline(lambda, pi0, df = smooth.df) : 
#  missing or infinite values in inputs are not allowed
> set.seed(2); x = rbeta(10, .5, .5); qvalue(x)$qvalues
#  [1] 0.951071387 0.659680351 0.758747866 0.659680351 0.300722417 0.758747866 0.005839447 0.758747866 0.517323547 0.182981819
gaow commented 1 year ago

@ajbass We ran into this as well. The line of code in question is:

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

and here is a minimal example to illustrate it:

> p = c(0.1,0.1,0.2,0.9,0.04,0.06)
> qvalue::pi0est(p, lambda=seq(0.1, 0.9, 0.05)) # works fine with this lambda setting
$pi0
[1] 1

$pi0.lambda
 [1] 0.7407407 0.3921569 0.4166667 0.2222222 0.2380952 0.2564103 0.2777778
 [8] 0.3030303 0.3333333 0.3703704 0.4166667 0.4761905 0.5555556 0.6666667
[15] 0.8333333 1.1111111 1.6666667

$lambda
 [1] 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80
[16] 0.85 0.90

$pi0.smooth
 [1] 0.4588714 0.4118555 0.3683073 0.3316308 0.3053646 0.2920991 0.2935659
 [8] 0.3110279 0.3455266 0.3979790 0.4691274 0.5593505 0.6683622 0.7948434
[15] 0.9361005 1.0879290 1.2450532

> qvalue::pi0est(p, lambda=seq(0.05, 0.95, 0.05))
Error in smooth.spline(lambda, pi0, df = smooth.df) : 
  missing or infinite values in inputs are not allowed
> lambda = seq(0.05, 0.95, 0.05)
> tabulate(findInterval(p, vec = lambda))
 [1] 1 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1
> length(tabulate(findInterval(p, vec = lambda)))
[1] 17
> length(lambda)
[1] 19
> ind = length(lambda):1
> tabulate(findInterval(p, vec = lambda))[ind]
 [1] NA NA  1  0  0  0  0  0  0  0  0  0  0  0  0  1  0  2  1
> qvalue(p)
Error in smooth.spline(lambda, pi0, df = smooth.df) : 
  missing or infinite values in inputs are not allowed

Could you please take a look at it and help us with the issue? Thank you!

Edit: related issues are #22 and #24 and a solution is posted in #22 to fix pi0est rather than to estimate it. This makes sense for interactive analysis we can always poke around to solve it one way or another. But we are building this into a pipeline to analyze many molecular QTL studies. It would be great if the behavior can be improved from within the software package.

ajbass commented 1 year ago

Sorry for the delay. @gaow that's too few p-values to estimate q-values (you need a few hundred). On the other hand, you can use the solution in #22 which would be equivalent to BH p-values. If you have a few hundred p-values but they are less than 0.95 (the max lambda threshold) then you can try something likelambda=seq(0.1, max(p) - 0.05, 0.05) in your pipeline.