Cumulative distribution functions?

P

PJ

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.
 
A

A. Sinan Unur

(e-mail address removed) (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).

CPAN is your friend:

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

PJ

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

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";
 
A

A. Sinan Unur

(e-mail address removed) (PJ) wrote in
CPAN, of course, is the first place I checked. Most of the time, it is
your friend...

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:

(e-mail address removed) (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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top