Home > wafo > wstats > wchi2fit.m

wchi2fit

PURPOSE ^

Parameter estimates for Chi squared data.

SYNOPSIS ^

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

DESCRIPTION ^

 WCHI2FIT Parameter estimates for Chi squared data.
 
  CALL: [phat, var] = wchi2fit(data, plotflag)
 
      phat = [df] = the maximum likelihood estimate of the  
             parameter of the Chi^2 distribution (see wchi2pdf)
             given the data.
      var  = asymptotic variance of the estimate 
      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=wchi2rnd(2,1,100);
    phat = wchi2fit(R,2) 
 
  See also  wchi2cdf, empdistr

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [phat, cov,pci]=wchi2fit(data1, plotflag);
002 %WCHI2FIT Parameter estimates for Chi squared data.
003 %
004 % CALL: [phat, var] = wchi2fit(data, plotflag)
005 %
006 %     phat = [df] = the maximum likelihood estimate of the  
007 %            parameter of the Chi^2 distribution (see wchi2pdf)
008 %            given the data.
009 %     var  = asymptotic variance of the estimate 
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=wchi2rnd(2,1,100);
017 %   phat = wchi2fit(R,2) 
018 %
019 % See also  wchi2cdf, empdistr
020 
021 % No Reference
022 %  
023 
024 % tested on: matlab 5.3
025 % History:
026 % By  pab 24.10.2000
027 % revised PJ 03-Apr-2001
028 %  - fmins changed name to fminsearch for version >= 5.3
029 
030 
031 error(nargchk(1,2,nargin))
032 if nargin<2|isempty(plotflag),plotflag=1;end
033 
034 data = data1(:); % make sure it is a vector
035 
036 mu   = mean(data);
037 sa   = std(data)^2;
038 
039 % Supply a starting guess with method of moments:
040 phat0 = max((mu+sa/2)/2,1);
041 
042 mvrs=version;ix=find(mvrs=='.');
043 if str2num(mvrs(1:ix(2)-1))>5.2,
044   phat = round(fminsearch('loglike',phat0,optimset,data,1,'wchi2pdf'));
045 else
046   phat = round(fmins('loglike',phat0,[],[],data,1,'wchi2pdf'));
047 end
048 
049 phat = [phat-1 phat phat+1] +(phat==1);
050 LL(1) = loglike(phat(1),data,'wtpdf');
051 LL(2) = loglike(phat(2),data,'wtpdf');
052 LL(3) = loglike(phat(3),data,'wtpdf');
053 [Y,ind] = min(LL);
054 phat = phat(ind);
055 
056 
057 if nargout>1,
058   [LL, cov] = loglike(phat,data,'wchi2pdf');
059 end
060 if nargout>2
061   alpha2 = ones(1,1)*0.05/2;
062   var = cov;
063   pci = wnorminv([alpha2;1-alpha2], [phat;phat],[var;var]);
064 end
065 
066 if plotflag 
067   sd = sort(data); 
068   empdistr(sd,[sd, wchi2cdf(sd,phat)],plotflag)
069   title([deblank(['Empirical and Chi squared estimated cdf'])])
070 end
071

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