lognfit

Lognormal parameter estimates

Description

pHat = lognfit(x) returns unbiased estimates of lognormal distribution parameters, given the sample data in x. pHat(1) and pHat(2) are the mean and standard deviation of logarithmic values, respectively.

[pHat,pCI] = lognfit(x) also returns 95% confidence intervals for the parameter estimates.

example

[pHat,pCI] = lognfit(x,alpha) specifies the confidence level for the confidence intervals to be 100(1–alpha)%.

example

[___] = lognfit(x,alpha,censoring) specifies whether each value in x is right-censored or not. Use the logical vector censoring in which 1 indicates observations that are right-censored and 0 indicates observations that are fully observed. With censoring, the phat values are the maximum likelihood estimates (MLEs).

[___] = lognfit(x,alpha,censoring,freq) specifies the frequency or weights of observations.

example

[___] = lognfit(x,alpha,censoring,freq,options) specifies optimization options for the iterative algorithm lognfit to use to compute MLEs with censoring. Create options by using the function statset.

You can pass in [] for alpha, censoring, and freq to use their default values.

Examples

collapse all

Generate 1000 random numbers from the lognormal distribution with the parameters 5 and 2.

rng('default') % For reproducibility
n = 1000; % Number of samples
x = lognrnd(5,2,n,1);

Find the parameter estimates and the 99% confidence intervals.

[pHat,pCI] = lognfit(x,0.01)
pHat = 1×2

4.9347    1.9979

pCI = 2×2

4.7717    1.8887
5.0978    2.1196

pHat(1) and pHat(2) are the mean and standard deviation of logarithmic values, respectively. pCI contains the 99% confidence intervals of the mean and standard deviation parameters. The values in the first row are the lower bounds, and the values in the second row are the upper bounds.

Find the MLEs of a data set with censoring by using lognfit. Use statset to specify the iterative algorithm options that lognfit uses to compute MLEs for censored data, and then find the MLEs again.

Generate the true times x that follow the lognormal distribution with the parameters 5 and 2.

rng('default') % For reproducibility
n = 1000; % Number of samples
x = lognrnd(5,2,n,1);

Generate the censoring times. Note that the censoring times must be independent of the true times x.

censtime = normrnd(150,20,size(x));

Specify the indicator for the censoring times and the observed times.

censoring = x>censtime;
y = min(x,censtime);

Find the MLEs of the lognormal distribution parameters. The second input argument of lognfit specifies the confidence level. Pass in [] to use its default value 0.05. The third input argument specifies the censorship information.

pHat = lognfit(y,[],censoring)
pHat = 1×2

4.9535    1.9996

Display the default algorithm parameters that lognfit uses to estimate the lognormal distribution parameters.

statset('lognfit')
ans = struct with fields:
Display: 'off'
MaxFunEvals: 200
MaxIter: 100
TolBnd: 1.0000e-06
TolFun: 1.0000e-08
TolTypeFun: []
TolX: 1.0000e-08
TolTypeX: []
Jacobian: []
DerivStep: []
FunValCheck: []
Robust: []
RobustWgtFun: []
WgtFun: []
Tune: []
UseParallel: []
UseSubstreams: []
Streams: {}
OutputFcn: []

Save the options using a different name. Change how the results are displayed (Display) and the termination tolerance for the objective function (TolFun).

options = statset('lognfit');
options.Display = 'final';
options.TolFun = 1e-10;

Alternatively, you can specify algorithm parameters by using the name-value pair arguments of the function statset.

options = statset('Display','final','TolFun',1e-10);

Find the MLEs with the new algorithm parameters.

pHat = lognfit(y,[],censoring,[],options)
Successful convergence: Norm of gradient less than OPTIONS.TolFun
pHat = 1×2

4.9535    1.9996

lognfit displays a report on the final iteration.

Input Arguments

collapse all

Sample data, specified as a vector.

Data Types: single | double

Significance level for the confidence intervals, specified as a scalar in the range (0,1). The confidence level is 100(1—alpha)%, where alpha is the probability that the confidence intervals do not contain the true value.

Example: 0.01

Data Types: single | double

Indicator for the censoring of each value in x, specified as a logical vector of the same size as x. Use 1 for observations that are right-censored and 0 for observations that are fully observed.

The default is an array of 0s, meaning that all observations are fully observed.

Data Types: logical

Frequency or weights of observations, specified as a nonnegative vector that is the same size as x. The freq input argument typically contains nonnegative integer counts for the corresponding elements in x, but can contain any nonnegative values.

To obtain the weighted MLEs for a data set with censoring, specify weights of observations, normalized to the number of observations in x.

The default is an array of 1s, meaning one observation per element of x.

Data Types: single | double

Optimization options, specified as a structure. options determines the control parameters for the iterative algorithm that lognfit uses to compute MLEs for censored data.

Create options by using the function statset or by creating a structure array containing the fields and values described in this table.

Field NameValueDefault Value
Display

Amount of information displayed by the algorithm.

• 'off' — Displays no information.

• 'final' — Displays the final output.

'off'
MaxFunEvals

Maximum number of objective function evaluations allowed, specified as a positive integer.

200
MaxIter

Maximum number of iterations allowed, specified as a positive integer.

100
TolBnd

Lower bound of the standard deviation parameter estimate, specified as a positive scalar.

The bounds for the mean and standard deviation parameter estimates are [–Inf,Inf] and [TolBnd,Inf], respectively.

1e-6
TolFun

Termination tolerance for the objective function value, specified as a positive scalar.

1e-8
TolX

Termination tolerance for the parameters, specified as a positive scalar.

1e-8

You can also enter statset('lognfit') in the Command Window to see the names and default values of the fields that lognfit accepts in the options structure.

Example: statset('Display','final','MaxIter',1000) specifies to display the final information of the iterative algorithm results, and change the maximum number of iterations allowed to 1000.

Data Types: struct

Output Arguments

collapse all

Estimates of lognormal distribution parameters, returned as a 1-by-2 vector. pHat(1) and pHat(2) are the mean and standard deviation of logarithmic values, respectively.

• With no censoring, the pHat values are unbiased estimates. To compute the MLEs with no censoring, use the mle function.

• With censoring, the pHat values are the MLEs. To compute the weighted MLEs, specify the weights of observations by using freq.

Confidence intervals for parameter estimates of the lognormal distribution, returned as a 2-by-2 matrix containing the lower and upper bounds of the 100(1–alpha)% confidence intervals.

The first and second rows correspond to the lower and upper bounds of the confidence intervals, respectively.

Algorithms

To compute the confidence intervals, lognfit uses the exact method for uncensored data and the Wald method for censored data. The exact method provides exact coverage for uncensored samples based on t and chi-square distributions.

Alternative Functionality

lognfit is a function specific to lognormal distribution. Statistics and Machine Learning Toolbox™ also offers the generic functions mle, fitdist, and paramci and the Distribution Fitter app, which support various probability distributions.

• mle returns MLEs and the confidence intervals of MLEs for the parameters of various probability distributions. You can specify the probability distribution name or a custom probability density function.

• Create a LognormalDistribution probability distribution object by fitting the distribution to data using the fitdist function or the Distribution Fitter app. The object properties mu and sigma store the parameter estimates. To obtain the confidence intervals for the parameter estimates, pass the object to paramci.

 Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.

 Lawless, J. F. Statistical Models and Methods for Lifetime Data. Hoboken, NJ: Wiley-Interscience, 1982.

 Meeker, W. Q., and L. A. Escobar. Statistical Methods for Reliability Data. Hoboken, NJ: John Wiley & Sons, Inc., 1998.