Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inverse poisson using perl (Math::CDF) 1

Status
Not open for further replies.

spperl

Programmer
Mar 29, 2005
34
0
0
GB
Hi,

I'm work on probabilities and I'm looking for a perl module that mimics the excel POISSON(x,mean,cumulative) function where cumulative = False.

The only module I have come across that is close is the Math::CDF distribution however by default the this works with cumulative probabilities which unfortunately for my purpose is no good.

I would be interested to know if anyone has came across this scenario before or has any useful tips or pointers?

Thanks
spperl
 
Though this is not at all efficient, you can calculate the local value from two cumulatives: POISSON(x,mean,TRUE)-POISSON(x-1,mean,TRUE).
However the POISSON function is quite simple to code: in the module Math::BigFloat you have the factorial function, if you need to use big numbers, otherwise that's quite simple to code (untested).
Code:
sub Poisson{
  my($x,$mu)=@_;
  return exp(-$x)*$mu**$x/fact($x);
}
sub fact{
  my($n)=@_;
  my($p,$i);
  $p=1;
  for($i=2;$i<=$n;$i++){$p*=$i}
  return$p;
}
}
Of course this doesn't account for overflow conditions. If you know in advance your upper limits on $x and $mu you can code them as error tests into the functions. Also note that this code will return an answer also if $x is not integer, however the result wouldn't be correct: you should test that $x is integer and positive.

: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
Hi,

Thanks for your reply and taking the time to do this. I did end up coding manually.

So thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top