This is a good question which I got stuck on as well.
Suppose $X$ is lognormal defined as $X\sim \log \mathcal{N}(\mu, \sigma^2)$. With this notation we mean that if we write $X = e^Z$, then $Z$ follows a normal distribution with mean $\mu$ and variance $\sigma^2$.
The mean and variance of $X$ are then $\mu_X = e^{\mu + \frac{1}{2}\sigma^2}$ and $\sigma_X^2 = (e^{\sigma^2} - 1)e^{2\mu + \sigma^2}$.
For many distributions the location and scale parameters are just the standard mean and variance. This is not the case for the lognormal distribution. You can look up the details somewhere else (everything follows from the definition of the PDF), but what it comes down to is (see also here):
- The lognormal's shape parameters equals the normal's scale parameter (the standard deviation of $Z$: $\sigma_Z$)
- The lognormal's scale parameter equals the normal's exponentiated location parameter ($e^{\mu_Z}$)
- The lognormal's location parameter does not have a counterpart on the normal distribution side. A lognormal distribution with non-zero location parameter cannot be written as the exponential of a normal distribution. The distribution has a lower bound at zero, and with a non-zero location parameter this lower bound is shifted left or right.
TLDR: On to python. Here's two ways of sampling from the lognormal distribution with $\mu_Z = 5$ and $\sigma_Z=.2$, one of which shows how you instantiate the lognorm
class.
from scipy.stats import lognorm, norm
import numpy as np
import matplotlib.pyplot as plt
mu = 5.
stdev = .2
Z = norm(loc=mu, scale=stdev)
X = lognorm(s=stdev, scale=np.exp(mu))
plt.hist(np.exp(Z.rvs(10000)), bins=100)
plt.hist(X.rvs(10000), bins=100)
Note that loc
defaults to zero for $X$.