Bug 14710 - qchisq produced NaN when df=0.00991
qchisq produced NaN when df=0.00991
Status: RESOLVED DUPLICATE of bug 8528
Product: R
Classification: Unclassified
Component: Misc
R 2.11.1
Other Other
: P5 enhancement
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-21 17:55 UTC by Jun Luo
Modified: 2011-10-22 07:46 UTC (History)
1 user (show)

See Also:


Attachments
bug.report (1.19 KB, application/octet-stream)
2011-10-21 17:55 UTC, Jun Luo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jun Luo 2011-10-21 17:55:11 UTC
Created attachment 1241 [details]
bug.report

y=qchisq(p=0.05/2,df=0.0099);# good
z=qchisq(p=0.05/2,df=0.01); # good
x=qchisq(p=0.05/2,df=0.00991); 
# NaN produced, please advise how we can handle this
Comment 1 Peter Dalgaard 2011-10-21 19:39:20 UTC
It  is basically caused by ungraceful underflow:

> qchisq(p=0.05/2,df=seq(0.009875, 0.009925,,101))
  [1]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
  [5]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
  [9]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [13]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [17]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [21]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [25]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [29]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [33]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [37]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [41]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [45]  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00
 [49]  0.000000e+00  0.000000e+00           NaN           NaN
 [53]           NaN           NaN           NaN           NaN
 [57]           NaN           NaN           NaN           NaN
 [61]           NaN           NaN           NaN           NaN
 [65]           NaN           NaN           NaN           NaN
 [69]           NaN           NaN           NaN           NaN
 [73]           NaN           NaN           NaN           NaN
 [77]           NaN           NaN           NaN 9.881313e-324
 [81] 9.881313e-324 9.881313e-324 9.881313e-324 9.881313e-324
 [85] 9.881313e-324 9.881313e-324 9.881313e-324 9.881313e-324
 [89] 9.881313e-324 9.881313e-324 9.881313e-324 9.881313e-324
 [93] 9.881313e-324 1.482197e-323 1.482197e-323 1.482197e-323
 [97] 1.482197e-323 1.482197e-323 1.482197e-323 1.482197e-323
[101] 1.482197e-323
Warning message:
In qchisq(p, df, lower.tail, log.p) : NaNs produced


It beats me why anyone would be interested in the behavior for that sort of argument, but replacing the NaN with zero looks like a fairly reasonable workaround.
Comment 2 Brian Ripley 2011-10-22 07:46:59 UTC
It is an instance of PR#8528: that third-party code tries to do
a Newton step at -Inf and 'improves' it to NaN.

Simply skipping the 'improvement' solves it.

*** This bug has been marked as a duplicate of bug 8528 ***