## Algorithm for Areas Under Normal Curve

For the discussion of math. Duh.

Moderators: gmalivuk, Moderators General, Prelates

fagricipni
Posts: 41
Joined: Thu Nov 04, 2010 7:32 pm UTC

### Algorithm for Areas Under Normal Curve

In my statistics classes, we used tables like this one to calculate areas under the normal curve. What I want is a algorithm that can be programmed that will calculate the area between a positive z-score and positive infinity, and the z-score for a area between a positive z-score and infinity. I.e., area(2.0) will return .0228 and z(.0228) will return 2.0. I suspect that these functions will involve infinite series or iterations. I am particularly interested in large z-scores and small areas; e.g. area(10.0) and z(1e-9). So algorithms that preserve precision in these extreme cases are to be desired. I have the standard functions that one would find on a simple scientific calculator: basic four, powers, roots, natural log, e^, sin, cos, tan, arcsin, arccos, arctan, and hyperbolic versions of the last six.

Xanthir
My HERO!!!
Posts: 5400
Joined: Tue Feb 20, 2007 12:49 am UTC
Contact:

### Re: Algorithm for Areas Under Normal Curve

Don't feel like searching out algos at the moment, but what you're looking for is high-precision algorithms for the CDF of the normal distribution. That's usually stated as the area between -∞ and your z-score, but that's just (1 - your-thing).
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

Flumble
Yes Man
Posts: 2236
Joined: Sun Aug 05, 2012 9:35 pm UTC

### Re: Algorithm for Areas Under Normal Curve

The hard part you're looking for is called the error function (erf) and its inverse, the probit.

But before you go programming these functions, find out if there's a statistics library available in <your language of choice> that already implements them. For example, the (kind of widely available) GNU MPFR library includes an erf function.

Cleverbeans
Posts: 1378
Joined: Wed Mar 26, 2008 1:16 pm UTC

### Re: Algorithm for Areas Under Normal Curve

You can integrate the Taylor series of the normal distribution to the desired degree of accuracy.
"Labor is prior to, and independent of, capital. Capital is only the fruit of labor, and could never have existed if labor had not first existed. Labor is the superior of capital, and deserves much the higher consideration." - Abraham Lincoln

fagricipni
Posts: 41
Joined: Thu Nov 04, 2010 7:32 pm UTC

### Re: Algorithm for Areas Under Normal Curve

I have found a solution to my current problem. I have found something that goes one way: area(z)=erfc(z/sqrt(2))/2. erfc is needed because (1-erf(z/sqrt(2)))/2 loses precision for high z values. I can go the other way by using the fact that the function is monotonic, and do a binary search for a value to the needed level of precision. This is good enough for my current purposes.