question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What are the input arguments “s” and “scale” defined in scipy.stats.lognorm? (scipy.stats.lognorm documentation error)

See original GitHub issue

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

The second description paragraph of scipy.stats.lognorm states the following:

“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).”

This paragraph is confusing and seems to state the mean = mu and standard deviation = sigma.

The correct answer is s = shape factor and scale = median value, as shown in the below example. Note, Wikipedia defines the shape factor as mu and median value as exp(mu).

Reproducing code example:

from scipy.stats import *
import numpy as np

#Log-Normal distribution
mu = 1.0          #mean
sigma = 0.5       #Std Dev

zeta = np.sqrt(np.log(1 + (sigma / mu) ** 2)) #shape factor
lambda_value = np.log(mu) - 0.5 * zeta ** 2   # expected value of ln x

median = np.exp(lambda_value)
print('Mean      ', lognorm.mean(s=zeta, loc=0, scale=np.exp(lambda_value)))
print('Median    ', median)
print('Median2   ', lognorm.median(s=zeta, loc=0, scale=np.exp(lambda_value)))
print('Quantile1 ', lognorm.ppf(0.9, s=zeta, loc=0, scale=np.exp(lambda_value)))
print('Quantile2 ', lognorm.ppf(0.2, s=zeta, loc=0, scale=np.exp(lambda_value)))

Mean       1.0
Median     0.8944271909999159
Median2    0.8944271909999159
Quantile1  1.6385447242959015
Quantile2  0.6010137742068968

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  ...

Scipy/Numpy/Python version information:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mdhabercommented, Dec 20, 2020

@tbgs2020 Thanks for mentioning this. I’ll go ahead and close for now, since it looks like the question was answered by @rkern. If you think that the documentation can be improved, please take a look at my suggested wording above, or let us know how you think it should read. Thanks!

0reactions
mdhabercommented, Dec 19, 2020

@WarrenWeckesser what do you think of this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

scipy.stats.lognorm — SciPy v1.9.3 Manual
lognorm takes s as a shape parameter for s . The probability density above is defined in the “standardized” form. To shift and/or...
Read more >
scipy, lognormal distribution - parameters - Stack Overflow
For the two parameter lognormal distribution, the "mean" and "std dev" ... the model will be scipy.stats.lognorm(s=sigmaX, loc=0, scale=muX) ...
Read more >
numpy.random.lognormal — NumPy v1.24 Manual
mean and standard deviation >>> s = np.random.lognormal(mu, sigma, 1000) ... b = np.array(b) / np.min(b) # scale values to be positive >>>...
Read more >
scipy.stats.stats — Elephant 0.7.0 documentation
[CRCProbStat2000] Zwillinger, D. and Kokoska, S. (2000). ... 2.0 * math.sqrt(2.0)} def iqr(x, axis=None, rng=(25, 75), scale='raw', nan_policy='propagate', ...
Read more >
scipy.stats._continuous_distns — Copulas 0.6.0 documentation
_ccallback import LowLevelCallable from scipy import optimize from scipy ... so that c=abs(L)/S) ## ## note: regress docs have scale parameter correct, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found