truncLognormal {VGAMextra} | R Documentation |
The Truncated Log-Normal Distribution
Description
Density, distribution function, quantile function and random generation for the truncated log-normal distribution
Usage
dtrunclnorm(x, meanlog = 0, sdlog = 1, min.support = 0, max.support = Inf, log = FALSE)
ptrunclnorm(q, meanlog = 0, sdlog = 1, min.support = 0, max.support = Inf)
qtrunclnorm(p, meanlog = 0, sdlog = 1, min.support = 0, max.support = Inf, log.p = FALSE)
rtrunclnorm(n, meanlog = 0, sdlog = 1, min.support = 0, max.support = Inf)
Arguments
x , q , p , n , meanlog , sdlog |
Same as |
min.support , max.support |
Lower and upper truncation limits. |
log , log.p |
Same as |
Details
Consider Y \sim
Lognormal
(\mu_Y, \sigma_Y )
restricted
to (A, B )
,
that is, 0 < A = \code{min.support} < X < B
= \code{max.support}
.
The (conditional)
random variable
Y = X \cdot I_{(A , B)}
has a log–truncated normal distribution. Its p.d.f. is given by
f(y; \mu, \sigma, A, B) = (y^{-1} / \sigma) \cdot
\phi(y^*) / [ \Phi(B^*) - \Phi(A^*) ],
where y^* = [\log(y) - \mu_Y]/ \sigma_Y
,
A^* = [\log(A) - \mu_Y] / \sigma_Y
,
and
B^* = [\log(B) - \mu_Y] / \sigma_Y
.
Its mean is:
\exp(\mu + \sigma^2/2) \cdot \{\Phi[(\log(B) - \mu) / \sigma
- \sigma] - \Phi[(\log(A) - \mu) / \sigma
- \sigma] \} / \{
\Phi[(\log(B) - \mu) / \sigma] - \Phi[(\log(A) - \mu) / \sigma] \}.
Here, \Phi
is the standard normal c.d.f and
\phi
is the standard normal p.d.f.
Value
dtrunclnorm()
returns the density,
ptrunclnorm()
gives the
distribution function,
qtrunclnorm()
gives the quantiles, and
rtrunclnorm()
generates random deviates.
Author(s)
Victor Miranda and Thomas W. Yee.
References
Johnson, N. L., Kotz, S. and Balakrishnan, N. (1995) Continuous Univariate Distributions, Second Edition, (Chapter 13) Wiley, New York.
See Also
Examples
###############
## Example 1 ##
mymeanlog <- exp(0.5) # meanlog
mysdlog <- exp(-1.5) # sdlog
LL <- 3.5 # Lower bound
UL <- 8.0 # Upper bound
## Quantiles:
pp <- 1:10 / 10
(quants <- qtrunclnorm(p = pp , min.support = LL, max.support = UL,
mymeanlog, mysdlog))
sum(pp - ptrunclnorm(quants, min.support = LL, max.support = UL,
mymeanlog, mysdlog)) # Should be zero
###############
## Example 2 ##
set.seed(230723)
nn <- 3000
## Truncated log-normal data
trunc_data <- rtrunclnorm(nn, mymeanlog, mysdlog, LL, UL)
## non-truncated data - reference
nontrunc_data <- rtrunclnorm(nn, mymeanlog, mysdlog, 0, Inf)
## Not run:
## Densities
plot.new()
par(mfrow = c(1, 2))
plot(density(nontrunc_data), main = "Non-truncated Log--normal",
col = "green", xlim = c(0, 15), ylim = c(0, 0.40))
abline(v = c(LL, UL), col = "black", lwd = 2, lty = 2)
plot(density(trunc_data), main = "Truncated Log--normal",
col = "red", xlim = c(0, 15), ylim = c(0, 0.40))
## Histograms
plot.new()
par(mfrow = c(1, 2))
hist(nontrunc_data, main = "Non-truncated Log--normal", col = "green",
xlim = c(0, 15), ylim = c(0, 0.40), freq = FALSE, breaks = 22,
xlab = "mu = exp(0.5), sd = exp(-1.5), LL = 3.5, UL = 8")
abline(v = c(LL, UL), col = "black", lwd = 4, lty = 2)
hist(trunc_data, main = "Truncated Log--normal", col = "red",
xlim = c(0, 15), ylim = c(0, 0.40), freq = FALSE,
xlab = "mu = exp(0.5), sd = exp(-1.5), LL = 3.5, UL = 8")
## End(Not run)
## Area under the estimated densities
# (a) truncated data
integrate(approxfun(density(trunc_data)),
lower = min(trunc_data) - 0.1,
upper = max(trunc_data) + 0.1)
# (b) non-truncated data
integrate(approxfun(density(nontrunc_data)),
lower = min(nontrunc_data),
upper = max(nontrunc_data))