Path: blob/main/Lessons/Lesson 10 - Simulation/extras/lognormal.ipynb
871 views
A note on lognormal distributions
When we use the lognormal normal distribution to generate random values like
We're actually specifying the mean and standard deviation for the underlying normal distribution and then taking the exponential of of those random numbers. So the logarithm of our random numbers will have mean mu
and standard deviation sigma
. To see how this works lets compute a sample of 10 random numbers two different ways. We're going to specify and . We'll reset a random number seed each time to see how the results compare. First we'll generate 10 normally distributed random numbers and apply the exponential function.
Notice those numbers can't possibly come from a distribution whose mean is 8, but if we were to take the log of those numbers:
Those numbers could come from a distribution with mean 8. When we specify a random variable is lognormal distributed with mean and standard deviation it means that the logarithm of the random variable follows a normal distribution with the specified parameters.
The second method for generating the lognormal random numbers is to just use the lognormal distribution from numpy:
Notice that these are exactly the same random numbers as we generated using the first approach. Suppose we want the lognormal distribution to have mean and standard deviation then we need to reverse engineer the parameters and for the underlying normal distribution:
You can find these formulas in a variety of places, including Wikipedia.
To generate a sample of 1000 observations from a lognormal distribution with mean 8 and standard deviation 3 we could do this:
Of course the mean and standard deviation of the sample aren't exactly 8 and 3, respectively but that is just the usual sampling variability.