Every now and then, just for fun, I like to code up a standard statistical test using C#. When doing so, it’s fairly common to need to programmatically calculate the area under the Normal (aka Gaussian, aka bell-shaped) distribution.
I tend to use one of two different algorithms. The first is equation 7.1.26 from the famous A&S reference book. The second equation uses ACM Algorithm #206. I’ve compared the results of the two algorithms in the past and noticed that they give slightly different (typically in the 8th decimal point) results. This makes sense because both techniques are just approximations.
I wondered how the R language calculates Normal area. So, I used the R language pnorm() function to print the area under the standard Normal (mean = 0, sd = 1) distribution for z values from -4.0 to +4.0. Then I coded a C# program to do the same using the A&S algorithm and the ACM algorithm.
My results indicate that the R language most likely uses the ACM algorithm. I don’t think this is too important, however, from now on if I want to validate C# code using R, I’ll use the ACM algorithm.