关于使用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?
[4]Fitting log-normal distribution in R vs. SciPy
http://stats.stackexchange.com/questions/33036/fitting-log-normal-distribution-in-r-vs-scipy
最新文章
- Java下好用的开源库推荐
- html图标插件
- nignx 启动,重启命令
- iOS 开发之使用safari对webview进行调试
- 分享11个纯css完成的图片浏览器
- Jmeter进行数据库压测
- js中加密及设置cookie
- python实现websocket服务器,可以在web实时显示远程服务器日志
- premake 在64位Ubuntu系统下编译32位GCC程序
- swift label不同颜色、不同字体
- 分享一次Oracle数据导入导出经历
- 【转】sed 高级用法
- 修改hosts不必重启 立刻生效
- centOS 安装gitlab-runner
- 常用cursor光标说明
- [SQL]SQL Prompt5的工具栏按钮介绍
- BTC和BCH 区别和联系?
- Docker关联使用的一些工具:Clip名字服务(转载)
- redis 介绍
- shiro+spring相关配置