Home > wafo > wstats > wtweibfit.m

# wtweibfit

## PURPOSE

Parameter estimates for truncated Weibull data.

## SYNOPSIS

[phat, cov, pci]=wtweibfit(data1, plotflag);

## DESCRIPTION

``` WTWEIBFIT Parameter estimates for truncated Weibull data.

CALL:  [phat, cov] = wtweibfit(data, plotflag)

phat = [a,b,c] = the Least Squares estimates of the
parameters of the truncated  Weibull distribution
(see wtweibcdf) given the data.
cov  = asymptotic covariance matrix of estimates
data = data vector
plotflag = 0, do not plot
> 0, plot the empiricial distribution function and the
estimated cdf (see empdistr for options)(default)

Example:
R=wweibrnd(2,2,1,200);
R=R(R>1)-1;  % Truncated weibul with a=2, b=2, c=1
[phat, cov] = wtweibfit(R)

## CROSS-REFERENCE INFORMATION

This function calls:
 empdistr Computes and plots the empirical CDF loglike Log-likelihood function. wnorminv Inverse of the Normal distribution function wtweibcdf Truncated Weibull cumulative distribution function wweibfit Parameter estimates for Weibull data. deblank Remove trailing blanks. error Display message and abort function. fmins fminsearch Multidimensional unconstrained nonlinear minimization (Nelder-Mead). interp1 1-D interpolation (table lookup) linspace Linearly spaced vector. optimset Create/alter OPTIM OPTIONS structure. str2num Convert string matrix to numeric array. title Graph title. version MATLAB version number.
This function is called by:
 dist2dfit Parameter estimates for DIST2D data.

## SOURCE CODE

```001 function [phat, cov, pci]=wtweibfit(data1, plotflag);
002 %WTWEIBFIT Parameter estimates for truncated Weibull data.
003 %
004 % CALL:  [phat, cov] = wtweibfit(data, plotflag)
005 %
006 %     phat = [a,b,c] = the Least Squares estimates of the
007 %            parameters of the truncated  Weibull distribution
008 %            (see wtweibcdf) given the data.
009 %     cov  = asymptotic covariance matrix of estimates
010 %     data = data vector
011 % plotflag = 0, do not plot
012 %          > 0, plot the empiricial distribution function and the
013 %               estimated cdf (see empdistr for options)(default)
014 %
015 % Example:
016 %   R=wweibrnd(2,2,1,200);
017 %   R=R(R>1)-1;  % Truncated weibul with a=2, b=2, c=1
018 %   [phat, cov] = wtweibfit(R)
019 %
021
022 % Reference: Cohen & Whittle, (1988) "Parameter Estimation in Reliability
023 % and Life Span Models", p. 25 ff, Marcel Dekker.
024
025 %Tested on: matlab  5.3
026 % History:
027 % revised pab July2004
028 % revised pab Dec2003
029 % revised pab 03.11.2000
031 % revised pab 24.10.2000
032 %  - added nargchk + safer call to fzero
033 %  - made sure data is a vector
034 % rewritten ms 20.06.2000
035
036 error(nargchk(1,2,nargin))
037 if nargin<2|isempty(plotflag),  plotflag=1; end
038
039 data  = data1(:);                            % make sure it is a vector
040 N     = length(data);
041
042 sd = sort(data);
043
044 F = [0.5./N:1./N:(N - 0.5)./N]';
045 if N>10000
046   Fi = linspace(F(1),F(end-5),10000).';
047   %Fi = fliplr(logspace(log10(F(end)),log10(F(1)),10000)).';
048   sd =interp1(F,sd,Fi,'linear');
049   F  = Fi;
050 end
051 phat0 = wweibfit(sd,0);
052
053
054 %g0=inline('mean((-log(1-F)+((data+abs(x(3)))./x(1)).^x(2)-abs(x(3)/x(1)).^x(2)).^2 )','x','data','F');
055
056
057 monitor = logical(0);
058
059 def=2; % PJ Added. What is def? See 'wtweibfun'
060 mvrs=version;ix=find(mvrs=='.');
061 if str2num(mvrs(1:ix(2)-1))>5.2,
062   phat = fminsearch('wtweibfun',[phat0,0],optimset,sd,F,def,monitor);
063 else
064   phat =  fmins('wtweibfun',[phat0,0],[],[],sd,F,def,monitor);
065 end
066
067 %phat =  fminsearch('g0',[phat0,0],[],F,sd);
068 %phat  = fmins('loglike',[phat0,1],[],[],data,'wtweibpdf');
069
070 if nargout>1,
071   [L,cov]= loglike(phat,data,'wtweibpdf');
072 end
073 if nargout>2,
074   var=diag(cov)';
075   alpha2=ones(1,3)*0.05/2;
076   pci = wnorminv([alpha2;1-alpha2],[phat;phat],[var;var]);
077 end
078
079
080 if plotflag
081   empdistr(sd,[sd, wtweibcdf(sd,phat(1),phat(2),phat(3))],plotflag)
082   title([deblank(['Empirical and truncated Weibull estimated cdf'])])
083 end
084
085
086
087```

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