# macroeco.models.lognorm¶

macroeco.models.lognorm = <macroeco.models._distributions.lognorm_gen object at 0x108661a90>

A lognormal random variable.

$f(x) = \frac{1}{\sigma x \sqrt{2 \pi}} e^{(\log{x} - \mu)^2 / 2 \sigma^2}$
Parameters: x : array_like quantiles q : array_like lower or upper tail probability mu, sigma : array_like shape parameters loc : array_like, optional location parameter (default=0) scale : array_like, optional scale parameter (default=1) size : int or tuple of ints, optional shape of random variates (default computed from input arguments ) moments : str, optional composed of letters [‘mvsk’] specifying which moments to compute where ‘m’ = mean, ‘v’ = variance, ‘s’ = (Fisher’s) skew and ‘k’ = (Fisher’s) kurtosis. (default=’mv’) Alternatively, the object may be called (as a function) to fix the shape, : location, and scale parameters returning a “frozen” continuous RV object: : rv = lognorm(mu, sigma, loc=0, scale=1) : Frozen RV object with the same methods but holding the given shape, location, and scale fixed. mu : float mu parameter of lognormal distribution. Mean log(x) sigma : float sigma parameter of lognormal distribution. sd of log(x)

Examples

>>> import macroeco.models as md
>>> import numpy as np

>>> # Given mean = 20 and sigma = 2, get the parameters for the lognormal
>>> md.lognorm.translate_args(20, 2)
(0.99573227355399085, 2)

>>> # Define a lognormal distribution
>>> lgnorm = md.lognorm(mu=0.99573227355399085, sigma=2)

>>> # Get the PDF
>>> lgnorm.pdf(np.linspace(0.1, 100, num=10))
array([  5.12048368e-01,   1.38409265e-02,   5.13026600e-03,
2.71233007e-03,   1.68257934e-03,   1.14517879e-03,
8.28497146e-04,   6.26026253e-04,   4.88734158e-04,
3.91396174e-04])

>>> # Get the stats for the lognormal
>>> lgnorm.stats()
(array(19.99935453933589), array(21437.87621568711))

>>> # Similarly you could use
>>> md.lognorm.stats(mu=0.99573227355399085, sigma=2)
(array(20.0), array(21439.260013257688))

>>> # Draw some random numbers from the lognormal
>>> samp = md.lognorm.rvs(mu=1.5, sigma=1.3, size=100)

>>> # Fit model to data
>>> md.lognorm.fit_mle(samp)
(1.2717334369626212, 1.3032723732257057)

>>> # Get the rank abundance distribution for a lognormal for 10 species
>>> md.lognorm.rank(10, 1.5, 1.3)
array([  0.52818445,   1.16490157,   1.86481775,   2.71579138,
3.806234  ,   5.27701054,   7.39583206,  10.77077745,
17.24226102,  38.02750505])


Methods

 rvs(mu, sigma, loc=0, scale=1, size=1) Random variates. pdf(x, mu, sigma, loc=0, scale=1) Probability density function. logpdf(x, mu, sigma, loc=0, scale=1) Log of the probability density function. cdf(x, mu, sigma, loc=0, scale=1) Cumulative density function. logcdf(x, mu, sigma, loc=0, scale=1) Log of the cumulative density function. sf(x, mu, sigma, loc=0, scale=1) Survival function (1-cdf — sometimes more accurate). logsf(x, mu, sigma, loc=0, scale=1) Log of the survival function. ppf(q, mu, sigma, loc=0, scale=1) Percent point function (inverse of cdf — percentiles). isf(q, mu, sigma, loc=0, scale=1) Inverse survival function (inverse of sf). moment(n, mu, sigma, loc=0, scale=1) Non-central moment of order n stats(mu, sigma, loc=0, scale=1, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’). entropy(mu, sigma, loc=0, scale=1) (Differential) entropy of the RV. fit(data, mu, sigma, loc=0, scale=1) Parameter estimates for generic data. expect(func, mu, sigma, loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds) Expected value of a function (of one argument) with respect to the distribution. median(mu, sigma, loc=0, scale=1) Median of the distribution. mean(mu, sigma, loc=0, scale=1) Mean of the distribution. var(mu, sigma, loc=0, scale=1) Variance of the distribution. std(mu, sigma, loc=0, scale=1) Standard deviation of the distribution. interval(alpha, mu, sigma, loc=0, scale=1) Endpoints of the range that contains alpha percent of the distribution