commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Guha, Rajarshi (NIH/NCATS) [C]" <gu...@mail.nih.gov>
Subject Re: [math] hypergeometric distribution giving incorrect results
Date Tue, 04 Sep 2012 19:08:11 GMT
Thanks for the pointers everybody

On Sep 4, 2012, at 2:30 PM, Brent Worden wrote:

> Additional numerical error could be surfacing with your use of
> Math.log.  For your case, it might be better to use
> Math.log1p(-d.cumulativeProbability(7)) instead.  For small values,
> log1p reportedly provides better accuracy.
> 
> Thanks,
> 
> Brent
> 
> 
> On Tue, Sep 4, 2012 at 1:21 AM, Thomas Neidhart
> <thomas.neidhart@gmail.com> wrote:
>> On 09/04/2012 04:14 AM, Guha, Rajarshi (NIH/NCATS) [C] wrote:
>>> Hi, I'm using  commons math 2.2 and the values from the hypergeometric distribution
do not seem to match an alternative implementation (from R 2.15.1). The code I'm using is
>>> 
>>>        HypergeometricDistributionImpl d =
>>>              new HypergeometricDistributionImpl(2550, 61, 8);
>>>        double logp = Math.log(1 - d.cumulativeProbability(7));
>>> 
>>> Using JDK 1.6.1, logp comes out to be -30.258290927468533
>>> 
>>> However, on R 2.15.1 when doing
>>> 
>>>      phyper(7, 61, 2489, 8, lower=F, log.p=T)
>>> 
>>> I get -30.33188
>>> 
>>> This seems to be a pretty big difference and in the project that I'm using commons-math
prevents me from porting some R code to Java.
>>> 
>>> Can anybody confirm these results? Is this a bug? Or am I invoking something
in the wrong way?
>> 
>> Hi,
>> 
>> there have been several improvements made to the Hypergeometric
>> distribution in the latest trunk version of commons math (3.1, to be
>> released soon).
>> 
>> I tried your example and get the following result:
>> 
>> logp = -30.333226371742285
>> 
>> Best regards,
>> 
>> Thomas
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 

--
Rajarshi Guha | http://blog.rguha.net
NIH Center for Advancing Translational Science


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message