lognfit
Estimate parameters and confidence intervals for the lognormal distribution.
paramhat = lognfit (x)
returns the maximum likelihood
estimates of the parameters of the lognormal distribution given the data in
vector x. paramhat([1, 2])
corresponds to the mean and
standard deviation, respectively, of the associated normal distribution.
If a random variable follows this distribution, its logarithm is normally distributed with mean mu and standard deviation sigma.
[paramhat, paramci] = lognfit (x)
returns the 95%
confidence intervals for the parameter estimates.
[…] = lognfit (x, alpha)
also returns the
100 * (1 - alpha)
percent confidence intervals for the
parameter estimates. By default, the optional argument alpha is
0.05 corresponding to 95% confidence intervals. Pass in []
for
alpha to use the default values.
[…] = lognfit (x, alpha, censor)
accepts a
boolean vector, censor, of the same size as x with 1
s for
observations that are right-censored and 0
s for observations that are
observed exactly. By default, or if left empty,
censor = zeros (size (x))
.
[…] = lognfit (x, alpha, censor, freq)
accepts a frequency vector, freq, of the same size as x.
freq typically contains integer frequencies for the corresponding
elements in x, but it can contain any non-integer non-negative values.
By default, or if left empty, freq = ones (size (x))
.
[…] = lognfit (…, options)
specifies control
parameters for the iterative algorithm used to compute ML estimates with the
fminsearch
function. options is a structure with the following
fields and their default values:
options.Display = "off"
options.MaxFunEvals = 400
options.MaxIter = 200
options.TolX = 1e-6
With no censor, the estimate of the standard deviation,
paramhat(2)
, is the square root of the unbiased estimate of the
variance of log (x)
. With censored data, the maximum
likelihood estimate is returned.
Further information about the lognormal distribution can be found at https://en.wikipedia.org/wiki/Log-normal_distribution
See also: logncdf, logninv, lognpdf, lognrnd, lognlike, lognstat
Source Code: lognfit
## Sample 3 populations from 3 different log-normal distibutions randn ("seed", 1); # for reproducibility r1 = lognrnd (0, 0.25, 1000, 1); randn ("seed", 2); # for reproducibility r2 = lognrnd (0, 0.5, 1000, 1); randn ("seed", 3); # for reproducibility r3 = lognrnd (0, 1, 1000, 1); r = [r1, r2, r3]; ## Plot them normalized and fix their colors hist (r, 30, 2); h = findobj (gca, "Type", "patch"); set (h(1), "facecolor", "c"); set (h(2), "facecolor", "g"); set (h(3), "facecolor", "r"); hold on ## Estimate their mu and sigma parameters mu_sigmaA = lognfit (r(:,1)); mu_sigmaB = lognfit (r(:,2)); mu_sigmaC = lognfit (r(:,3)); ## Plot their estimated PDFs x = [0:0.1:6]; y = lognpdf (x, mu_sigmaA(1), mu_sigmaA(2)); plot (x, y, "-pr"); y = lognpdf (x, mu_sigmaB(1), mu_sigmaB(2)); plot (x, y, "-sg"); y = lognpdf (x, mu_sigmaC(1), mu_sigmaC(2)); plot (x, y, "-^c"); ylim ([0, 2]) xlim ([0, 6]) hold off legend ({"Normalized HIST of sample 1 with mu=0, σ=0.25", ... "Normalized HIST of sample 2 with mu=0, σ=0.5", ... "Normalized HIST of sample 3 with mu=0, σ=1", ... sprintf("PDF for sample 1 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaA(1), mu_sigmaA(2)), ... sprintf("PDF for sample 2 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaB(1), mu_sigmaB(2)), ... sprintf("PDF for sample 3 with estimated mu=%0.2f and σ=%0.2f", ... mu_sigmaC(1), mu_sigmaC(2))}, "location", "northeast") title ("Three population samples from different log-normal distibutions") hold off |