clbustos / distribution

Statistical Distributions multi library wrapper. Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
Other
141 stars 52 forks source link

Chi-square q_chi2 range violation #21

Open apetrov opened 8 years ago

apetrov commented 8 years ago

2.1.6 :112 > Distribution::ChiSquare.q_chi2(4000, 1487) => 1.1715358426793223 2.1.6 :113 > Distribution::ChiSquare.q_chi2(4000, 1488) => 1.287980205519492 2.1.6 :114 > Distribution::ChiSquare.q_chi2(4000, 1489) => 1.0610471112556463 2.1.6 :115 > Distribution::ChiSquare.q_chi2(4000, 1490) => 1.7505434400435371 2.1.6 :116 > Distribution::ChiSquare.q_chi2(4000, 1491) => 0.0 2.1.6 :117 > Distribution::ChiSquare.q_chi2(4000, 1492) => 0.0

it is expected Distribution::ChiSquare.q_chi2 to be within [0..1] range

envp commented 8 years ago

I can see the same issue in SciRuby's master branch. Great catch!

Please add a pull request with tests for this to SciRuby's master branch

~/workspace (master) $ bundle exec irb
2.2.1 :001 > require 'distribution'                                                                                                                                                                                                        
 => true 
2.2.1 :002 > Distribution::ChiSquare.q_chi2(4000, 1487)
 => 1.1715358426793223 
2.2.1 :003 > Distribution::ChiSquare.q_chi2(4000, 1488)
 => 1.287980205519492 
2.2.1 :004 > Distribution::ChiSquare.q_chi2(4000, 1489)
 => 1.0610471112556463 
2.2.1 :005 > Distribution::ChiSquare.q_chi2(4000, 1490)
 => 1.7505434400435371 
2.2.1 :006 > Distribution::ChiSquare.q_chi2(4000, 1491)
 => 0.0 
2.2.1 :007 > Distribution::ChiSquare.q_chi2(4000, 1492)
 => 0.0 
oliver-czulo commented 10 months ago

Might it be the bug is around still? Here is what I get:

irb(main):010:0> Distribution::ChiSquare.q_chi2(1, 69)
=> 0.0
irb(main):011:0> Distribution::ChiSquare.q_chi2(1, 68)
=> 0.0
irb(main):012:0> Distribution::ChiSquare.q_chi2(1, 67)
=> 0.0
irb(main):013:0> Distribution::ChiSquare.q_chi2(1, 66)
=> 4.440892098500626e-16

If there is any branch that solves this, would be greatful for a pointer.