Log-normal distribution#
Taking the exponential of a Normal random variable with mean \(\lambda\) and standard deviation \(\zeta\) gives a log-normal random variable; i.e., the natural logarithm of the random variable follows a Normal distribution.
In the following, let \(X\) be a random variable that follows a \emph{log-normal} distribution with parameters \(\lambda\) and \(\zeta\), and let \(x\) denote a particular outcome of \(X\). If the distribution of \(X\) is shifted by parameter \(\varepsilon\), the distribution is referred to as shifted log-normal distribution (If not mentioned explicitly, this parameter equals zero).
import fesslix as flx
flx.load_engine()
import numpy as np
import fesslix.plot as flx_plot
import matplotlib.pyplot as plt
%matplotlib inline
Random Number Generator: MT19937 - initialized with rand()=1222282124;
Random Number Generator: MT19937 - initialized with 1000 initial calls.
Syntax#
- property logn#
Log-normal distribution
lognis a distribution type (flx_rv_type) for Random variables in Fesslix.- Parametrization:
Parameters of the distribution can be specified as additional key-value pairs in an object of type
flx_rv_config. The following combinations of parameters are accepted:mu,sdlambda,zetamode,sdmedian,sdmedian,covmode,covval_1,pr_1,val_2,pr_2cov,val_1,pr_1
Additionally, the key-value pair
epsilonis allowed for any parametrization.The interpretation of the parameters is:
mu(flxParaPosNo0): mean value; only positive values larger than epsilon are allowedsd(flxParaPosNo0): standard deviationepsilon(flxParaPos0, default: 0.0): right-shift of distributionmode(flxParaPosNo0): mode of distribution; only positive values larger than epsilon are allowedmedian(flxParaPosNo0): median of distribution; only positive values larger than epsilon are allowedcov(flxParaPosNo0): coefficient of variation. If epsilon is set, the cov is interpreted ascov=sd/(mu-epsilon).lambda(flxPara): mean value of the underlying Normal distributionzeta(flxParaPosNo0): standard deviation of the underlying Normal distributionval_1(flxParaPosNo0):pr_1quantile`pr_1(flxParaPr): probability that the value of the distribution is smaller or equal than val_1val_2(flxParaPosNo0):pr_2quantile`pr_2(flxParaPr): probability that the value of the distribution is smaller or equal than val_2
Example:
rv_1 = flx.rv({'name':'rv_1', 'type':'logn', 'mu':2., 'sd':5. })
rv_2 = flx.rv({'name':'rv_2', 'type':'logn', 'lambda':0., 'zeta':1. })
rv_3 = flx.rv({'name':'rv_3', 'type':'logn', 'mode':2., 'sd':5. })
rv_4 = flx.rv({'name':'rv_4', 'type':'logn', 'median':2., 'sd':5. })
rv_5 = flx.rv({'name':'rv_5', 'type':'logn', 'mode':2., 'cov':1. })
rv_6 = flx.rv({'name':'rv_6', 'type':'logn', 'median':2., 'cov':1. })
rv_7 = flx.rv({'name':'rv_7', 'type':'logn', 'cov':0.1, 'val_1':2.5, 'pr_1':0.05 })
rv_8 = flx.rv({'name':'rv_8', 'type':'logn', 'val_1':2.5, 'pr_1':0.05, 'val_2':3.2, 'pr_2':0.5 })
rv_lst = [ rv_1, rv_2, rv_3, rv_4, rv_5, rv_6, rv_7, rv_8 ]
Properties#
- Notation
\(X\sim\mathrm{ln}\mathcal{N}(\lambda,\zeta,\varepsilon) = \exp\left[\mathcal{N}\left(\lambda,\zeta\right)\right]+\varepsilon\)
- Parameters
\(\lambda\in\mathbb{R}\), \(\zeta\in(0,\infty)\), \(\varepsilon\in\mathbb{R}\)
- Support
\(x\in(\varepsilon,\infty)\)
- Mean
\(\mu_X = \exp\left(\lambda+\frac{\zeta^2}{2}\right) + \varepsilon\)
- Standard deviation
\(\sigma_X = \sqrt{\exp\left(\zeta^2\right)-1} \cdot \exp\left(\lambda+\frac{\zeta^2}{2}\right)\)
- Median
\(\exp\left(\lambda\right) + \varepsilon\)
- Mode
\(\exp\left(\lambda-\zeta^2\right) + \varepsilon\)
- Skewness
\(\left( \exp\left(\zeta^2\right)+2 \right) \cdot \sqrt{\exp\left(\zeta^2\right)-1}\)
- Excess kurtosis
\(\exp\left(4\zeta^2\right) + 2\exp\left(3\zeta^2\right) + 3\exp\left(2\zeta^2\right) - 6\)
- Entropy
\(\frac{1}{2} + \frac{1}{2}\ln\left(2\pi \zeta^2\right) + \lambda\)
PDF#
The PDF \(f_X(x)\) of the log-normal distribution is:
The PDF \(f_X(x)\) can also be expressed in terms of the PDF of the Standard Normal distribution \(\varphi(\cdot)\):
x_up = 8.
fig, ax = plt.subplots(figsize=(10, 4))
for rv in rv_lst:
flx_plot.draw_pdf(ax, rv, config_dict={'label':rv.get_name(), 'x_low':1e-6, 'x_up':x_up})
ax.set_ylim([0., None])
ax.set_xlim([0., x_up])
plt.xlabel(r"$x$")
plt.ylabel(r"$f_X(x)$")
plt.legend()
plt.show()
CDF#
The CDF \(F_X(x)\) of the log-normal distribution is defined as:
where \(\Phi(\cdot)\) is the CDF of the Standard Normal distribution.
x_up = 8.
fig, ax = plt.subplots(figsize=(10, 4))
for rv in rv_lst:
flx_plot.draw_cdf(ax, rv, config_dict={'label':rv.get_name(), 'x_low':1e-6, 'x_up':x_up})
ax.set_ylim([0., 1.])
ax.set_xlim([0., x_up])
plt.xlabel(r"$x$")
plt.ylabel(r"$F_X(x)$")
plt.legend()
plt.show()
Quantile function#
The quantile function of the log-normal distribution is:
where \(\Phi^{-1}(\cdot)\) is the quantile function of the Standard Normal distribution.
Standardizing Normal random variables#
The log-normal random variable \(X\) can be transformed to a Standard Normal distribution \(U\) through:
Conversely, a log-normal random variable \(X\) with parameters \(\lambda\) and \(\zeta\) can be generated from a standard Normal variable as:
Parametrization in terms of \(\mu_X\) and \(\sigma_X\)#
If the mean and standard deviation are given, the parameters \(\lambda\) and \(\zeta\) can be derived as: