[SciPy-User] specify lognormal distribution with mu and sigma using scipy.stats
Armando Serrano Lombillo
Wed Jul 21 07:13:58 CDT 2010
Hello, I'm also having difficulties with lognorm.
If mu is the mean and s**2 is the variance then...
>>> from scipy.stats import lognorm
>>> from math import exp
>>> mu = 10
>>> s = 1
>>> d = lognorm(s, scale=exp(mu))
shouldn't that be 10?
On Wed, Oct 14, 2009 at 3:20 PM, <email@example.com> wrote:
> On Wed, Oct 14, 2009 at 4:22 AM, Mark Bakker <firstname.lastname@example.org> wrote:
> > Hello list,
> > I am having trouble creating a lognormal distribution with known mean mu
> > standard deviation sigma using scipy.stats
> > According to the docs, the programmed function is:
> > lognorm.pdf(x,s) = 1/(s*x*sqrt(2*pi)) * exp(-1/2*(log(x)/s)**2)
> > So s is the standard deviation. But how do I specify the mean? I found
> > information that when you specify loc and scale, you replace x by
> > (x-loc)/scale
> > But in the lognormal distribution, you want to replace log(x) by
> > where loc is mu. How do I do that? In addition, would it be a good idea
> > create some convenience functions that allow you to simply create
> > (and maybe normal) distributions by specifying the more common mu and
> > That would surely make things more userfriendly.
> > Thanks,
> > Mark
> I don't think loc of lognorm makes much sense in most application,
> since it is just shifting the support, lower boundary is zero+loc. The
> loc of the underlying normal distribution enters through the scale.
> see also
> >>> print stats.lognorm.extradoc
> Lognormal distribution
> lognorm.pdf(x,s) = 1/(s*x*sqrt(2*pi)) * exp(-1/2*(log(x)/s)**2)
> for x > 0, s > 0.
> If log x is normally distributed with mean mu and variance sigma**2,
> then x is log-normally distributed with shape paramter sigma and scale
> parameter exp(mu).
> roundtrip with mean mu of the underlying normal distribution (scale=1):
> >>> mu=np.arange(5)
> >>> np.log(stats.lognorm.stats(1, loc=0,scale=np.exp(mu)))-0.5
> array([ 0., 1., 2., 3., 4.])
> corresponding means of lognormal distribution
> >>> stats.lognorm.stats(1, loc=0,scale=np.exp(mu))
> array([ 1.64872127, 4.48168907, 12.18249396, 33.11545196, 90.0171313
> shifting support:
> >>> stats.lognorm.a
> >>> stats.lognorm.ppf([0, 0.5, 1], 1, loc=3,scale=1)
> array([ 3., 4., Inf])
> The only case that I know for lognormal is in regression, so I'm not
> sure what you mean by the convenience functions.
> (the normal distribution is defined by loc=mean, scale=standard deviation)
> assume the regression equation is
> y = x*beta*exp(u) u distributed normal(0, sigma^2)
> this implies
> ln y = ln(x*beta) + u which is just a standard linear regression
> equation which can be estimated by ols or mle
> exp(u) in this case is lognormal distributed
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User