The Lognormal distribution is an absolute continuous probability distribution of a random variable whose logarithm is normally distributed. It is defined by parameters \(\mu\) and \(\sigma > 0\), which are the mean and standard deviation of the underlying normal distribution.
Usage
Lnorm(meanlog = 0, sdlog = 1)
# S4 method for class 'Lnorm,numeric'
d(distr, x, log = FALSE)
# S4 method for class 'Lnorm,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Lnorm,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)
# S4 method for class 'Lnorm,numeric'
r(distr, n)
# S4 method for class 'Lnorm'
mean(x)
# S4 method for class 'Lnorm'
median(x)
# S4 method for class 'Lnorm'
mode(x)
# S4 method for class 'Lnorm'
var(x)
# S4 method for class 'Lnorm'
sd(x)
# S4 method for class 'Lnorm'
skew(x)
# S4 method for class 'Lnorm'
kurt(x)
# S4 method for class 'Lnorm'
entro(x)
# S4 method for class 'Lnorm'
finf(x)
lllnorm(x, meanlog, sdlog)
# S4 method for class 'Lnorm,numeric'
ll(distr, x)
elnorm(x, type = "mle", ...)
# S4 method for class 'Lnorm,numeric'
mle(distr, x, na.rm = FALSE)
# S4 method for class 'Lnorm,numeric'
me(distr, x, na.rm = FALSE)
vlnorm(meanlog, sdlog, type = "mle")
# S4 method for class 'Lnorm'
avar_mle(distr)
# S4 method for class 'Lnorm'
avar_me(distr)
Arguments
- meanlog, sdlog
numeric. The distribution parameters.
- distr
an object of class
Lnorm
.- x
For the density function,
x
is a numeric vector of quantiles. For the moments functions,x
is an object of classLnorm
. For the log-likelihood and the estimation functions,x
is the sample of observations.- log, log.p
logical. Should the logarithm of the probability be returned?
- q
numeric. Vector of quantiles.
- lower.tail
logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).
- p
numeric. Vector of probabilities.
- n
number of observations. If
length(n) > 1
, the length is taken to be the number required.- type
character, case ignored. The estimator type (mle or me).
- ...
extra arguments.
- na.rm
logical. Should the
NA
values be removed?
Value
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (
distr
), thed()
,p()
,q()
,r()
,ll()
functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr
andx
), they evaluate the aforementioned functions directly.Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The
moments()
function returns a list with all the available methods.Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
Details
The probability density function (PDF) of the Lognormal distribution is: $$ f(x; \mu, \sigma) = \frac{1}{x \sigma \sqrt{2\pi}} e^{-\frac{(\log x - \mu)^2}{2 \sigma^2}}, \quad x > 0 .$$
Examples
# -----------------------------------------------------
# Lnorm Distribution Example
# -----------------------------------------------------
# Create the distribution
m <- 3 ; s <- 5
D <- Lnorm(m, s)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 2, 10)) # density function
#> [1] 0.186771116 0.035866376 0.007901606
p(D, c(0.3, 2, 10)) # distribution function
#> [1] 0.2002315 0.3222664 0.4445343
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 5.659098 1350.332541
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#> [1] 3.772171e-03 6.671290e-04 2.517216e-01 2.635158e-01 2.382044e-02
#> [6] 1.684454e-02 4.383061e-07 1.117212e+01 8.996097e-03 2.162057e-03
#> [11] 8.727851e-02 4.899467e-02 1.713367e-02 6.732309e-02 1.853741e-02
#> [16] 8.113191e-04 5.324813e-05 1.356071e-07 1.017682e-03 7.736096e-04
#> [21] 8.264750e-03 7.530464e-04 1.906528e-02 1.468408e-01 4.347717e-03
#> [26] 9.125370e-03 8.930959e-03 8.686833e-05 1.179629e-03 2.959542e+01
#> [31] 2.667211e-03 3.092216e-02 2.389078e-02 4.967730e-03 1.347887e-06
#> [36] 1.708972e-02 3.116280e-01 2.131902e-07 1.426817e-01 1.118841e-03
#> [41] 3.133833e-01 4.157483e-01 4.424566e-01 1.086775e-02 2.435180e-06
#> [46] 2.668187e-04 1.550838e+00 3.593631e-01 8.414336e-04 4.046170e-04
#> [51] 8.304027e-02 3.819082e+01 9.643371e-04 1.150166e-02 4.434309e-04
#> [56] 2.656873e-04 3.249186e-01 4.667622e-05 7.738186e-07 2.445277e-04
#> [61] 5.416448e-08 8.213517e-05 7.023487e-03 5.885826e-05 9.509842e-08
#> [66] 2.548425e-02 1.261995e-10 3.515978e-06 1.039084e+01 1.134171e-04
#> [71] 5.039501e-02 7.760113e-06 1.411286e-06 2.252489e-03 1.029574e-03
#> [76] 1.558956e-05 4.999391e-03 8.378587e-02 3.263977e-01 1.408740e-02
#> [81] 2.805362e+00 4.975963e-03 1.067992e-04 2.357552e-04 1.502800e-04
#> [86] 8.716583e-02 2.010319e-06 5.689029e-01 1.024153e-04 6.980956e-02
#> [91] 2.143243e-02 7.201897e-06 5.724365e-07 8.511594e-06 6.702402e-04
#> [96] 1.328477e+01 4.146778e-02 5.373587e-03 4.034312e-04 8.253889e-01
# ------------------
# Moments
# ------------------
mean(D) # Expectation
#> [1] 5389698
median(D) # Median
#> [1] 20.08554
mode(D) # Mode
#> [1] 2.789468e-10
var(D) # Variance
#> [1] 2.091659e+24
sd(D) # Standard Deviation
#> [1] 1.446257e+12
skew(D) # Skewness
#> [1] 1.93216e+16
kurt(D) # Excess Kurtosis
#> [1] 2.688117e+43
entro(D) # Entropy
#> [1] 8.697109
finf(D) # Fisher Information Matrix
#> meanlog sdlog
#> meanlog 0.2 0.0
#> sdlog 0.0 0.4
# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 5389698
# ------------------
# Point Estimation
# ------------------
elnorm(x, type = "mle")
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
elnorm(x, type = "me")
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
mle(D, x)
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
me(D, x)
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
e(D, x, type = "mle")
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
mle("lnorm", x) # the distr argument can be a character
#> $meanlog
#> [1] 3.10186
#>
#> $sdlog
#> [1] 4.823037
#>
# ------------------
# Estimator Variance
# ------------------
vlnorm(m, s, type = "mle")
#> meanlog sdlog
#> meanlog 5 0.0
#> sdlog 0 2.5
vlnorm(m, s, type = "me")
#> meanlog sdlog
#> meanlog 5 0.0
#> sdlog 0 2.5
avar_mle(D)
#> meanlog sdlog
#> meanlog 5 0.0
#> sdlog 0 2.5
avar_me(D)
#> meanlog sdlog
#> meanlog 5 0.0
#> sdlog 0 2.5
v(D, type = "mle")
#> meanlog sdlog
#> meanlog 5 0.0
#> sdlog 0 2.5