Home > wafo > wstats > wlognfit.m

# wlognfit

## PURPOSE

Parameter estimates for Lognormal data.

## SYNOPSIS

[phat, var,ciL,ciU] = wlognfit(data,plotflag)

## DESCRIPTION

``` WLOGNFIT Parameter estimates for Lognormal data.

CALL:  [phat var] = wlognfit(data, plotflag)

phat  = [m, v] = maximum likelihood estimate of the parameters of
the distribution (see wlognpdf)
var   = estimated asymptotic variance of phat (cov(m,v)=0)
data  = data matrix
plotflag = 0, do not plot
> 0, plot the empiricial distribution function and the
estimated cdf (see empdistr for options)(default)

Example:
R=wlognrnd(5,2,100,3);
[phat var]=wlognfit(R)```

## CROSS-REFERENCE INFORMATION

This function calls:
 empdistr Computes and plots the empirical CDF wchi2inv Inverse of the Chi squared distribution function wlogncdf Lognormal cumulative distribution function wtinv Inverse of the Student's T distribution function deblank Remove trailing blanks. error Display message and abort function. hold Hold current graph. mean Average or mean value. permute Permute array dimensions. title Graph title.
This function is called by:

## SOURCE CODE

```001 function [phat, var,ciL,ciU] = wlognfit(data,plotflag)
002 %WLOGNFIT Parameter estimates for Lognormal data.
003 %
004 % CALL:  [phat var] = wlognfit(data, plotflag)
005 %
006 %   phat  = [m, v] = maximum likelihood estimate of the parameters of
007 %           the distribution (see wlognpdf)
008 %   var   = estimated asymptotic variance of phat (cov(m,v)=0)
009 %   data  = data matrix
010 %plotflag = 0, do not plot
011 %         > 0, plot the empiricial distribution function and the
012 %              estimated cdf (see empdistr for options)(default)
013 %
014 % Example:
015 %   R=wlognrnd(5,2,100,3);
016 %   [phat var]=wlognfit(R)
017
018 % Reference: Cohen & Whittle, (1988) "Parameter Estimation in Reliability
019 % and Life Span Models", p. 59 ff, Marcel Dekker.
020
021
022
023 %tested on: matlab 5.x
024 % History:
025 % revised pab 24.10.2000
027 % - cov changed to var = variance since cov(m,v)=0
028 % - fixed some bugs when data is a matrix
030
031
032 error(nargchk(1,2,nargin))
033 if nargin<2|isempty(plotflag),  plotflag=1; end
034 sz = size(data);
035 Nsz=length(sz);
036 dim = min(find(sz~=1));  %1st non-singleton dimension
037 % make sure dim=1 is the first non-singleton dimension
038 if isempty(dim) | dim ~= 1,
039   order = [dim 1:dim-1 dim+1:Nsz];
040   data  = permute(data,order);
041   sz    = size(data);
042 end
043 m = prod(sz(2:end));
044 n =sz(1);
045 mhat=mean(log(data));
046 vhat=mean(log(data).^2)-mhat.^2;
047 phat=[mhat(:),vhat(:)];
048
049 var=[vhat(:), 2*vhat(:).^2]/n;
050
051 if nargout>2,
052   alpha2=ones(1,2)*0.05/2;
053   tcrit = wtinv([alpha2 1-alpha2],n-1);
054   chi2crit = wchi2inv([alpha2 1-alpha2],n-1);
055   ciL = [(mhat + tcrit(1)*sqrt(vhat/n)), sqrt(vhat*(n-1)./chi2crit(2))];
056   ciU = [(mhat + tcrit(2)*sqrt(vhat/n)), sqrt(vhat*(n-1)./chi2crit(1))];
057   %  ciL = wnorminv(alpha2(ones(m,1),:),phat,var);
058   %  ciU = wnorminv(1-alpha2(ones(m,1),:),phat,var);
059 end
060
061 if nargin < 2 | plotflag
062   sd=sort(data);
063   empdistr(sd(:,1),[sd(:,1),wlogncdf(sd(:,1),mhat(1),vhat(1))],plotflag ), hold on
064   for ix=2:m,empdistr(sd(:,ix),[sd(:,ix),wlogncdf(sd(:,ix),mhat(ix),vhat(ix))],plotflag),end
065    hold off
066   title([deblank(['Empirical and Lognormal estimated cdf'])])
067 end
068```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003