NAME
PDL::Stats::Distr -- parameter estimations and probability density functions for distributions.
DESCRIPTION
Parameter estimate is maximum likelihood estimate when there is closed form estimate, otherwise it is method of moments estimate.
SYNOPSIS
use PDL::LiteF;
use PDL::Stats::Distr;
# do a frequency (probability) plot with fitted normal curve
my $data = grandom(100)->abs;
my ($xvals, $hist) = $data->hist;
# turn frequency into probability
$hist /= $data->nelem;
# get maximum likelihood estimates of normal curve parameters
my ($m, $v) = $data->mle_gaussian();
# fitted normal curve probabilities
my $p = $xvals->pdf_gaussian($m, $v);
use PDL::Graphics::Simple;
my $win = pgswin();
$win->plot( with=>'bins', $hist, with=>'lines', style => 2, $p );
undef $win; # to close
Or, play with different distributions with plot_distr :)
$data->plot_distr( 'gaussian', 'lognormal' );
FUNCTIONS
mme_beta
Signature: (a(n); float+ [o]alpha(); float+ [o]beta())
Types: (float double ldouble)
my ($a, $b) = $data->mme_beta();
beta distribution. pdf: f(x; a,b) = 1/B(a,b) x^(a-1) (1-x)^(b-1)
Broadcasts over its inputs.
mme_beta processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_beta
Signature: (x(); a(); b(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_beta($x, $a, $b);
pdf_beta($x, $a, $b, $p); # all arguments given
$p = $x->pdf_beta($a, $b); # method call
$x->pdf_beta($a, $b, $p);
probability density function for beta distribution. x defined on [0,1].
Broadcasts over its inputs.
pdf_beta processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mme_binomial
Signature: (a(n); int [o]n_(); float+ [o]p())
Types: (float double ldouble)
my ($n, $p) = $data->mme_binomial;
binomial distribution. pmf: f(k; n,p) = (n k) p^k (1-p)^(n-k) for k = 0,1,2..n
Broadcasts over its inputs.
mme_binomial processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_binomial
Signature: (ushort x(); ushort n(); p(); float+ [o]out())
Types: (float double ldouble)
$out = pmf_binomial($x, $n, $p);
pmf_binomial($x, $n, $p, $out); # all arguments given
$out = $x->pmf_binomial($n, $p); # method call
$x->pmf_binomial($n, $p, $out);
probability mass function for binomial distribution.
Broadcasts over its inputs.
pmf_binomial processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_exp
Signature: (a(n); float+ [o]l())
Types: (float double ldouble)
my $lamda = $data->mle_exp;
exponential distribution. mle same as method of moments estimate.
Broadcasts over its inputs.
mle_exp processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_exp
Signature: (x(); l(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_exp($x, $l);
pdf_exp($x, $l, $p); # all arguments given
$p = $x->pdf_exp($l); # method call
$x->pdf_exp($l, $p);
probability density function for exponential distribution.
Broadcasts over its inputs.
pdf_exp processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mme_gamma
Signature: (a(n); float+ [o]shape(); float+ [o]scale())
Types: (float double ldouble)
my ($shape, $scale) = $data->mme_gamma();
two-parameter gamma distribution
Broadcasts over its inputs.
mme_gamma processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_gamma
Signature: (x(); a(); t(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_gamma($x, $a, $t);
pdf_gamma($x, $a, $t, $p); # all arguments given
$p = $x->pdf_gamma($a, $t); # method call
$x->pdf_gamma($a, $t, $p);
probability density function for two-parameter gamma distribution.
Broadcasts over its inputs.
pdf_gamma processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_gaussian
Signature: (a(n); float+ [o]m(); float+ [o]v())
Types: (float double ldouble)
my ($m, $v) = $data->mle_gaussian();
gaussian aka normal distribution. same results as $data->average and $data->var. mle same as method of moments estimate.
Broadcasts over its inputs.
mle_gaussian processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_gaussian
Signature: (x(); m(); v(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_gaussian($x, $m, $v);
pdf_gaussian($x, $m, $v, $p); # all arguments given
$p = $x->pdf_gaussian($m, $v); # method call
$x->pdf_gaussian($m, $v, $p);
probability density function for gaussian distribution.
Broadcasts over its inputs.
pdf_gaussian processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_geo
Signature: (a(n); float+ [o]p())
Types: (float double ldouble)
$p = mle_geo($a);
mle_geo($a, $p); # all arguments given
$p = $a->mle_geo; # method call
$a->mle_geo($p);
geometric distribution. mle same as method of moments estimate.
Broadcasts over its inputs.
mle_geo processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_geo
Signature: (ushort x(); p(); float+ [o]out())
Types: (float double ldouble)
$out = pmf_geo($x, $p);
pmf_geo($x, $p, $out); # all arguments given
$out = $x->pmf_geo($p); # method call
$x->pmf_geo($p, $out);
probability mass function for geometric distribution. x >= 0.
Broadcasts over its inputs.
pmf_geo processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_geosh
Signature: (a(n); float+ [o]p())
Types: (float double ldouble)
$p = mle_geosh($a);
mle_geosh($a, $p); # all arguments given
$p = $a->mle_geosh; # method call
$a->mle_geosh($p);
shifted geometric distribution. mle same as method of moments estimate.
Broadcasts over its inputs.
mle_geosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_geosh
Signature: (ushort x(); p(); float+ [o]out())
Types: (float double ldouble)
$out = pmf_geosh($x, $p);
pmf_geosh($x, $p, $out); # all arguments given
$out = $x->pmf_geosh($p); # method call
$x->pmf_geosh($p, $out);
probability mass function for shifted geometric distribution. x >= 1.
Broadcasts over its inputs.
pmf_geosh processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_lognormal
Signature: (a(n); float+ [o]m(); float+ [o]v())
Types: (float double ldouble)
my ($m, $v) = $data->mle_lognormal();
lognormal distribution. maximum likelihood estimation.
Broadcasts over its inputs.
mle_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mme_lognormal
Signature: (a(n); float+ [o]m(); float+ [o]v())
Types: (float double ldouble)
my ($m, $v) = $data->mme_lognormal();
lognormal distribution. method of moments estimation.
Broadcasts over its inputs.
mme_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_lognormal
Signature: (x(); m(); v(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_lognormal($x, $m, $v);
pdf_lognormal($x, $m, $v, $p); # all arguments given
$p = $x->pdf_lognormal($m, $v); # method call
$x->pdf_lognormal($m, $v, $p);
probability density function for lognormal distribution. x > 0. v > 0.
Broadcasts over its inputs.
pdf_lognormal processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mme_nbd
Signature: (a(n); float+ [o]r(); float+ [o]p())
Types: (float double ldouble)
my ($r, $p) = $data->mme_nbd();
negative binomial distribution. pmf: f(x; r,p) = (x+r-1 r-1) p^r (1-p)^x for x=0,1,2...
Broadcasts over its inputs.
mme_nbd processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_nbd
Signature: (ushort x(); r(); p(); float+ [o]out())
Types: (float double ldouble)
$out = pmf_nbd($x, $r, $p);
pmf_nbd($x, $r, $p, $out); # all arguments given
$out = $x->pmf_nbd($r, $p); # method call
$x->pmf_nbd($r, $p, $out);
probability mass function for negative binomial distribution.
Broadcasts over its inputs.
pmf_nbd processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mme_pareto
Signature: (a(n); float+ [o]k(); float+ [o]xm())
Types: (float double ldouble)
my ($k, $xm) = $data->mme_pareto();
pareto distribution. pdf: f(x; k,xm) = k xm^k / x^(k+1) for x >= xm > 0.
Broadcasts over its inputs.
mme_pareto processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pdf_pareto
Signature: (x(); k(); xm(); float+ [o]p())
Types: (float double ldouble)
$p = pdf_pareto($x, $k, $xm);
pdf_pareto($x, $k, $xm, $p); # all arguments given
$p = $x->pdf_pareto($k, $xm); # method call
$x->pdf_pareto($k, $xm, $p);
probability density function for pareto distribution. x >= xm > 0.
Broadcasts over its inputs.
pdf_pareto processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
mle_poisson
Signature: (a(n); float+ [o]l())
Types: (float double ldouble)
my $lamda = $data->mle_poisson();
poisson distribution. pmf: f(x;l) = e^(-l) * l^x / x!
Broadcasts over its inputs.
mle_poisson processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_poisson
Signature: (x(); l(); float+ [o]p())
Types: (float double ldouble)
$p = pmf_poisson($x, $l);
pmf_poisson($x, $l, $p); # all arguments given
$p = $x->pmf_poisson($l); # method call
$x->pmf_poisson($l, $p);
Probability mass function for poisson distribution. Uses Stirling's formula for x > 85.
Broadcasts over its inputs.
pmf_poisson processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_poisson_stirling
Signature: (x(); l(); [o]p())
Types: (float double ldouble)
$p = pmf_poisson_stirling($x, $l);
pmf_poisson_stirling($x, $l, $p); # all arguments given
$p = $x->pmf_poisson_stirling($l); # method call
$x->pmf_poisson_stirling($l, $p);
Probability mass function for poisson distribution. Uses Stirling's formula for all values of the input. See http://en.wikipedia.org/wiki/Stirling's_approximation for more info.
Broadcasts over its inputs.
pmf_poisson_stirling processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
pmf_poisson_factorial
Signature: (ushort x(); l(); float+ [o]p())
Types: (float double ldouble)
$p = pmf_poisson_factorial($x, $l);
pmf_poisson_factorial($x, $l, $p); # all arguments given
$p = $x->pmf_poisson_factorial($l); # method call
$x->pmf_poisson_factorial($l, $p);
Probability mass function for poisson distribution. Input is limited to x < 170 to avoid gsl_sf_fact() overflow.
Broadcasts over its inputs.
pmf_poisson_factorial processes bad values. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
plot_distr
Plots data distribution. When given specific distribution(s) to fit, returns % ref to sum log likelihood and parameter values under fitted distribution(s). See FUNCTIONS above for available distributions.
Default options (case insensitive):
MAXBN => 20,
# see PDL::Graphics::Simple for next options
WIN => undef, # pgswin object. not closed here if passed
# allows comparing multiple distr in same plot
# set env before passing WIN
COLOR => 1, # "style" for data distr
Usage:
# yes it threads :)
my $data = grandom( 500, 3 )->abs;
# ll on plot is sum across 3 data curves
my ($ll, $pars)
= $data->plot_distr( 'gaussian', 'lognormal' );
# pars are from normalized data (ie data / bin_size)
print "$_\t@{$pars->{$_}}\n" for (sort keys %$pars);
print "$_\t$ll->{$_}\n" for (sort keys %$ll);
DEPENDENCIES
GSL - GNU Scientific Library
SEE ALSO
AUTHOR
Copyright (C) 2009 Maggie J. Xiong <maggiexyz users.sourceforge.net>, David Mertens
All rights reserved. There is no warranty. You are allowed to redistribute this software / documentation as described in the file COPYING in the PDL distribution.