Essays/Normal CDF

From J Wiki
Jump to: navigation, search

The CDF of the standard normal N(0,1) distribution can be computed as follows. The results are accurate in the range from _7 to 7 .

erf   =: (1 H. 1.5)@*: * 2p_0.5&* % ^@:*:
n01cdf=: -: @ >: @ erf @ %&(%:2)

The following compares calculated results against values from the Handbook of Mathematical Functions by Abramowitz and Stegun, Table 26.1 for the normal CDF and Table 7.1 for the error function erf.

   t26d1=: 0.5 0.841344746068543 0.977249868051821 0.97500210485178 0.99505998424223
   x=: n01cdf 0 1 2 1.96 2.58
   0j15 ": x ,. t26d1
0.500000000000000 0.500000000000000
0.841344746068543 0.841344746068543
0.977249868051821 0.977249868051821
0.975002104851779 0.975002104851780
0.995059984242229 0.995059984242230

   t7d1=: 0 0.8427007929 0.9953222650 0.9944262755
   e=: erf 0 1 2 1.96
   0j15 0j10 ": e ,. t7d1
0.000000000000000 0.0000000000
0.842700792949715 0.8427007929
0.995322265018952 0.9953222650
0.994426275464828 0.9944262755



See also


Contributed by Roger Hui. erf and n01cdf are slight modifications from Ewart Shaw, Hypergeometric Functions and CDFs in J, Vector, Volume 18, Number 4, April 2002.