Converting Parameterizations of the Lognormal Distribution into the Standard Form
Written by Peter Rosenmai on 27 Feb 2021.
Below is a Python function to convert unconventional parameterizations of the lognormal distribution
into the standard parameterization. It takes the
(a) mean and median or
(b) mean and mode or
(c) median and mode
of a lognormal distribution and returns the mean and standard deviation of its underlying normal distribution.
Often when working on simulations, colleagues give me rough sketches of
probability distribution functions that they want me to use for random sampling.
These typically resemble lognormal distributions, so I find the function I
provide here to be quite useful.
import numpy as np
def get_lognormal_mu_sigma(logn_mean=None, logn_median=None, logn_mode=None):
if sum(param is not None for param in [logn_mean, logn_median, logn_mode]) != 2:
raise ValueError("Exactly two parameters must be supplied.")
if logn_mean and logn_median:
if logn_mean < logn_median:
raise ValueError("The mean cannot be less than the median.")
mu = np.log(logn_median)
sigma = np.sqrt(2 * (np.log(logn_mean) - np.log(logn_median)))
elif logn_mean and logn_mode:
if logn_mean < logn_mode:
raise ValueError("The mean cannot be less than the mode.")
mu = (np.log(logn_mode) + 2 * np.log(logn_mean)) / 3
sigma = np.sqrt(2 * (np.log(logn_mean) - np.log(logn_mode)) / 3)
else:
if logn_median < logn_mode:
raise ValueError("The median cannot be less than the mode.")
mu = np.log(logn_median)
sigma = np.sqrt(np.log(logn_median) - np.log(logn_mode))
return mu, sigma