distribution icon indicating copy to clipboard operation
distribution copied to clipboard

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

Open andreasmueller opened this issue 13 years ago • 1 comments

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.

andreasmueller avatar Dec 12 '12 14:12 andreasmueller

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

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

silverhammermba avatar Feb 19 '14 19:02 silverhammermba