关于使用scipy.stats.lognorm来模拟对数正态分布的误区

lognorm方法的参数容易把人搞蒙。例如lognorm.rvs(s, loc=0, scale=1, size=1)中的参数s,loc,scale, 要记住:loc和scale并不是我们通常理解的对数变化后数据的均值mu和标准差sigma,如下面所述:

The probability density function for lognorm is:
lognorm.pdf(x, s) = 1 / (s*x*sqrt(2*pi)) * exp(-1/2*(log(x)/s)**2) for x > 0, s > 0.
lognorm takes s as a shape parameter.
The probability density above is defined in the “standardized” form. To shift and/or scale the distribution use the loc and scale parameters. Specifically, lognorm.pdf(x, s, loc, scale) is identically equivalent to lognorm.pdf(y, s) / scale with y = (x - loc) / scale.
A common parametrization for a lognormal random variable Y is in terms of the mean, mu, and standard deviation, sigma, of the unique normally distributed random variable X such that exp(X) = Y. This parametrization corresponds to setting s = sigma and scale = exp(mu).

(源自参考文档2)

所以要得到一般意义上符合对数正态分布的随机变量X(即,logX服从n(mu,sigma^2)),需要令lognorm中的参数s=sigma,loc=0,scale=exp(mu)。(详细论述见参考文档3和4)

参考文档:

[1]如何在Python中实现这五类强大的概率分布

http://python.jobbole.com/81321/

[2]scipy.stats文档

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.lognorm.html#scipy.stats.lognorm

[3]How do I get a lognormal distribution in Python with Mu and Sigma?

http://stackoverflow.com/questions/8870982/how-do-i-get-a-lognormal-distribution-in-python-with-mu-and-sigma

[4]Fitting log-normal distribution in R vs. SciPy

http://stats.stackexchange.com/questions/33036/fitting-log-normal-distribution-in-r-vs-scipy

猜你喜欢

转载自www.cnblogs.com/lantingg/p/10025479.html