Cumulative distribution functions?

Discussion in 'Perl Misc' started by PJ, Nov 14, 2004.

  1. PJ

    PJ Guest

    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.
    PJ, Nov 14, 2004
    #1
    1. Advertising

  2. (PJ) wrote in
    news::

    > 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
    A. Sinan Unur, Nov 14, 2004
    #2
    1. Advertising

  3. PJ

    PJ Guest

    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. Sinan Unur" <> wrote in message news:<Xns95A1925FD08Fasu1cornelledu@132.236.56.8>...
    > (PJ) wrote in
    > news::
    >
    > > 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
    PJ, Nov 14, 2004
    #3
  4. (PJ) wrote in
    news::

    > 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:

    (PJ) wrote in
    news::

    > 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.
    A. Sinan Unur, Nov 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. papaja
    Replies:
    3
    Views:
    2,741
    Chris R. Timmons
    Feb 12, 2006
  2. tony lincoln

    to get Cumulative curves using java

    tony lincoln, Oct 16, 2003, in forum: Java
    Replies:
    1
    Views:
    364
    Phil...
    Oct 16, 2003
  3. Gary N.
    Replies:
    4
    Views:
    1,614
    Gary N.
    Feb 22, 2004
  4. Maggie

    Help with cumulative sum

    Maggie, Sep 8, 2009, in forum: Python
    Replies:
    13
    Views:
    594
    Andreas Waldenburger
    Sep 10, 2009
  5. Gery D. Dorazio
    Replies:
    0
    Views:
    143
    Gery D. Dorazio
    Aug 12, 2004
Loading...

Share This Page