Is there a Python method for calculating the lognormal mean and variance?

I am trying to figure out if there is a python built-in function to calculate the mean and variance. I require this information only to submit it to scipy.stats.lognorm for a chart overlaid on top of the histogram.

Just using numpy.mean and numpy.std does not seem to be the right idea, since the logarithmic mean and variance are specific and very different from numpy methods. In Matlab, they have a convenient function called lognstat that returns the mean and variance of the lognormal distribution, and I cannot find a similar method in Python. It's easy enough to encode work, but I wonder if this method exists in the library. Thanks.

+7
source share
2 answers

Whatever it costs, all lognstat in matlab does the following:

 import numpy as np def lognstat(mu, sigma): """Calculate the mean of and variance of the lognormal distribution given the mean (`mu`) and standard deviation (`sigma`), of the associated normal distribution.""" m = np.exp(mu + sigma**2 / 2.0) v = np.exp(2 * mu + sigma**2) * (np.exp(sigma**2) - 1) return m, v 

It might have a function for scipy.stats or scikits-statsmodels , but I don't know about that. In any case, this is just a couple of lines of code.

+5
source

(I don't have rpy install on my laptop at the moment, so I can’t try this)

You might consider installing Rpy , which is the python interface for R.

Then you can use this R function http://rss.acs.unt.edu/Rdoc/library/stats/html/Lognormal.html

0
source

All Articles