Jas*_*son 7 python statistics matlab
我试图了解是否有内置的python函数来计算对数正态均值和方差.我只需要这些信息然后将其输入到scipy.stats.lognorm叠加在直方图之上的图.
简单地使用numpy.mean并且numpy.std似乎不是正确的想法,因为对数正态均值和方差是特定的并且与numpy方法完全不同.在Matlab中,它们有一个方便的函数lognstat,它返回对数正态分布的均值和方差,而我似乎无法在Python中找到类似的方法.编写一个解决方案很容易,但我想知道这个方法是否存在于库中.谢谢.
无论它值多少,lognstatmatlab的所有内容都是这样的:
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
Run Code Online (Sandbox Code Playgroud)
可能有一个功能,scipy.stats或者scikits-statsmodels,但我没有意识到它.无论哪种方式,它只是几行代码.
(我的笔记本上目前没有安装 rpy,所以我无法尝试这个)
您可以考虑安装Rpy,它是 R 的 python 接口。
那么你也许可以使用这个R函数http://rss.acs.unt.edu/Rdoc/library/stats/html/Lognormal.html