Bug 17271 - phyper() returns NaN
Summary: phyper() returns NaN
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Accuracy (show other bugs)
Version: 3.4.0
Hardware: Other Linux
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2017-05-15 22:28 UTC by Alexey Stukalov
Modified: 2017-05-15 23:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey Stukalov 2017-05-15 22:28:21 UTC
On R 3.4.0:

> phyper(10, 14, 0, 11, log=FALSE)
[1] 0
> phyper(11, 15, 0, 12, log=FALSE)
[1] 0

> phyper(10, 14, 0, 11, log=TRUE)
[1] -Inf
> phyper(11, 15, 0, 12, log=TRUE)
[1] NaN
Warning message:
In phyper(11, 15, 0, 12, log = TRUE) : NaNs produced

The last command should also return -Inf.
Comment 1 Alexey Stukalov 2017-05-15 22:34:49 UTC
My guess is that in `phyper()` the value of pd = pdhyper(...) is some small negative number, which is why log() returns NaN.
Comment 2 Alexey Stukalov 2017-05-15 22:55:49 UTC
My previous comment was incorrect. Actually, in pdhyper(10, 14, 0, 11): sum = -1.0 and for phyper(11, 15, 0, 12): sum = -1.1, which makes log1p() generate NaN.
Comment 3 Alexey Stukalov 2017-05-15 23:00:27 UTC
The trivial fix would be to check d = dhyper().
If it's -Inf (for lop_p==TRUE case), then the phyper() result is -Inf and no pd = pdhyper() calculation is necessary. Same for d == 0 && lop_p == FALSE.

But it's not clear to me whether pdhyper() can give incorrect results for the other input parameters combinations.