Learn R Programming

joker (version 0.14.2)

Lnorm: Log-Normal Distribution

Description

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 Lnorm,numeric d(distr, x, log = FALSE)

# S4 method for Lnorm,numeric p(distr, q, lower.tail = TRUE, log.p = FALSE)

# S4 method for Lnorm,numeric qn(distr, p, lower.tail = TRUE, log.p = FALSE)

# S4 method for Lnorm,numeric r(distr, n)

# S4 method for Lnorm mean(x)

# S4 method for Lnorm median(x)

# S4 method for Lnorm mode(x)

# S4 method for Lnorm var(x)

# S4 method for Lnorm sd(x)

# S4 method for Lnorm skew(x)

# S4 method for Lnorm kurt(x)

# S4 method for Lnorm entro(x)

# S4 method for Lnorm finf(x)

lllnorm(x, meanlog, sdlog)

# S4 method for Lnorm,numeric ll(distr, x)

elnorm(x, type = "mle", ...)

# S4 method for Lnorm,numeric mle(distr, x, na.rm = FALSE)

# S4 method for Lnorm,numeric me(distr, x, na.rm = FALSE)

vlnorm(meanlog, sdlog, type = "mle")

# S4 method for Lnorm avar_mle(distr)

# S4 method for Lnorm avar_me(distr)

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), 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 and x), 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.

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 class Lnorm. 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?

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 .$$

See Also

Functions from the stats package: dlnorm(), plnorm(), qlnorm(), rlnorm()

Examples

Run this code
# -----------------------------------------------------
# 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
p(D, c(0.3, 2, 10)) # distribution function
qn(D, c(0.4, 0.8)) # inverse distribution function
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself

# ------------------
# Moments
# ------------------

mean(D) # Expectation
median(D) # Median
mode(D) # Mode
var(D) # Variance
sd(D) # Standard Deviation
skew(D) # Skewness
kurt(D) # Excess Kurtosis
entro(D) # Entropy
finf(D) # Fisher Information Matrix

# List of all available moments
mom <- moments(D)
mom$mean # expectation

# ------------------
# Point Estimation
# ------------------

elnorm(x, type = "mle")
elnorm(x, type = "me")

mle(D, x)
me(D, x)
e(D, x, type = "mle")

mle("lnorm", x) # the distr argument can be a character

# ------------------
# Estimator Variance
# ------------------

vlnorm(m, s, type = "mle")
vlnorm(m, s, type = "me")

avar_mle(D)
avar_me(D)

v(D, type = "mle")

Run the code above in your browser using DataLab