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

Normal distribution CDF gives wrong values for |x| > 38 #7

Open andreasmueller opened 11 years ago

andreasmueller commented 11 years ago

Distribution::Normal.cdf(-36) => 0.0 Distribution::Normal.cdf(-37) => 0.0 Distribution::Normal.cdf(-38) => 0.0 Distribution::Normal.cdf(-39) => 0.5 Distribution::Normal.cdf(38) => 1.0 Distribution::Normal.cdf(39) => 0.5

Since I just discovered that the Ruby Math library has an erf function, I switched to just using

0.5*(1.0+Math.erf(x.to_f/Math.sqrt(2.0)))

Maybe fixing this bug could help others, though.

silverhammermba commented 10 years ago

I also noticed this issue for the chi-square distribution.

Distribution::ChiSquare.q_chi2(3, 2000)
=> 1.0