# Cumulative distribution functions?

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I am going trough a book that uses that NORMDIST function in Excel.  I
would like to repoduce the results in perl.  Does anyone have a
function or module that is the same as Excel's NORMDIST?  Actually, I
only need the cumulative distribution function (in Excel's NORMDIST
function, the 4th parameter is set to TRUE).

As an example, normdist(42, 40, 1.5, TRUE) equals 0.908789.

I am using perl on a FreeBSD machine - so I don't have access to Excel
via perl.

I appreciate any help,

-Garrett.

p.s. This is Excel's documentation of the function:

NORMDIST

Returns the normal distribution for the specified mean and standard
deviation. This function has a very wide range of applications in
statistics, including hypothesis testing.

Syntax

NORMDIST(x,mean,standard_dev,cumulative)

X    is the value for which you want the distribution.

Mean    is the arithmetic mean of the distribution.

Standard_dev    is the standard deviation of the distribution.

Cumulative    is a logical value that determines the form of the
function. If cumulative is TRUE, NORMDIST returns the cumulative
distribution function; if FALSE, it returns the probability mass
function.

## Re: Cumulative distribution functions?

perlmod@yahoo.com (PJ) wrote in

> I am going trough a book that uses that NORMDIST function in Excel.  I
> would like to repoduce the results in perl.  Does anyone have a
> function or module that is the same as Excel's NORMDIST?  Actually, I
> only need the cumulative distribution function (in Excel's NORMDIST
> function, the 4th parameter is set to TRUE).

http://search.cpan.org/~mikek/Statistics-Distributions-
1.02/Distributions.pm

## Re: Cumulative distribution functions?

CPAN, of course, is the first place I checked. Most of the time, it is

The module you mention, Statistics::Distributions does not have a
corresponding function. Math::CDF is also lacking.

q/NORMDIST (x, mean, standard_dev, cumulative) returns the area under
the normal distribution up to point x where you have to define the
mean and SD of the population./

Now, there have been arguments posted on why not to use NORMDIST, but
I simply need to reproduce the examples in the book.

q/Microsoft chose to use a 6 polynomial approximation to the NORMSDIST
function (rather than the infinite series), and it is the worst of the
"DIST" functions. I have a nice graph that shows the error. So avoid
depending on these 3 "DIST" functions when sigma is more than 4./

Fortunately, I found Peter Acklam's Statistics::Distrib::Normal module
(requires his Math::SpecFun::Erf).  Why they are not posted on CPAN, I
don't know, but you can find them at
http://home.online.no/~pjacklam/perl/modules/index.html .

The following clode produces the same output as the NORMDIST example
given in MS Excel Help.

#!/usr/local/bin/perl -w

use strict;
use Statistics::Distrib::Normal;

my \$dist = Statistics::Distrib::Normal->new(mu => 40, sigma=> 1.5);
print \$dist->ltp(42) . "\n";

> perlmod@yahoo.com (PJ) wrote in
>
> > I am going trough a book that uses that NORMDIST function in Excel.  I
> > would like to repoduce the results in perl.  Does anyone have a
> > function or module that is the same as Excel's NORMDIST?  Actually, I
> > only need the cumulative distribution function (in Excel's NORMDIST
> > function, the 4th parameter is set to TRUE).
>
>
> http://search.cpan.org/~mikek/Statistics-Distributions-
> 1.02/Distributions.pm

## Re: Cumulative distribution functions?

perlmod@yahoo.com (PJ) wrote in

> CPAN, of course, is the first place I checked. Most of the time, it is
>
> The module you mention, Statistics::Distributions does not have a
> corresponding function.

Don't mess with distributions if you do not know statistics.

use strict;
use warnings;

use Statistics::Distributions;

my (\$mean, \$stdev) = (40, 1.5);
my \$z = (42 - \$mean)/\$stdev;
my \$p = 1 - Statistics::Distributions::uprob(\$z);
print "\$p\n";

D:\Home> perl st.pl
0.908789

To recall:

perlmod@yahoo.com (PJ) wrote in

> As an example, normdist(42, 40, 1.5, TRUE) equals 0.908789.

I am glad you found something that does what you want. But think before you
speak. Or, at least read the documentation for the module you are using
which shows how to get what you want from the module.

I am also going to suggest that you read the posting guidelines for this
group. Top-posting and full-quoting are not really appreciated here.

Sinan.