[BioPython] gamma distribution

Andrew Dalke dalke at xebte.pair.com
Fri Jun 18 13:15:12 EDT 2004


Hi Ernesto,

> I'm using the function gammavariate(a,b) from the random module, but
> I don't know really the interpretation of a and b. I guess a is the
> shape and b a scaling factor, so the mean should be a/b. Is my idea
> rigth?

I don't know but clues in the documentation and on usenet suggests
that http://mathworld.wolfram.com/GammaDistribution.html documents
the function.  That page states the mean is a*b.

You could also try it out.

>>> import random
>>> def gamma_mean(a, b, n = 1000):
...   data = [random.gammavariate(a, b) for i in range(n)]
...   return sum(data) / n, a*b
... 
>>> gamma_mean(0.1, 0.5)
(0.054523268939043509, 0.050000000000000003)
>>> gamma_mean(5, 9)
(44.813773895529096, 45)
>>> gamma_mean(20, 1.5)
(30.282363568363071, 30.0)
>>> 

So product it is, and not a/b.
                                        Andrew
                                        dalke at dalkescientific.com




More information about the BioPython mailing list