Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

lognormal distribution returns negative numbers #3418

Closed
ysanders opened this Issue · 5 comments

4 participants

@ysanders

If I try to generate random variables from the lognorm distribution, I seem to get the logarithm of the random variables rather than the random variables. For example,

from scipy.stats import lognorm
lognorm(.1,-1).rvs(10)

returns an array of ten floats near zero, some of which are negative. Calculating the exponential of this array yields an array of ten floats near 1.

Perhaps this is intentional behaviour, but I doubt it.

@argriffing
Collaborator

I'm pretty sure the -1 is treated as a location parameter. See http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.lognorm.html rv = lognorm(s, loc=0, scale=1). So lognorm(.1, -1).rvs(10) gives floats near 0, lognorm(.1, 0).rvs(10) gives floats near 1, and lognorm(.1, -10).rvs(10) gives floats near -9.

@ev-br
Collaborator

Just what Alex said:

>>> import numpy as np
>>> np.random.seed(123)
>>> lognorm.rvs(0.1, -1)
-0.10287767979642992
>>> 
>>> np.random.seed(123)
>>> lognorm.rvs(0.1, loc=-1)
-0.10287767979642992

Not a bug, hence closing. Questions are most welcome in the scipy-user mailing list and/or stackoverflow.

@ev-br ev-br closed this
@rgommers rgommers added the invalid label
@ysanders
@argriffing
Collaborator

@ysanders scipy.stats generalizes continuous distributions to translated and to spread-out variants of the original distribution. The -1 argument in your function is a translation. So this changes the support. Any distribution supported on the positive real numbers can be translated in this way so that the support of its translated distribution can include negative numbers. If you want to sample from lognormal distributions with the original support (positive real numbers) then don't pass -1 as the location parameter.

@ysanders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.