Home > wafo > wstats > wnormfit.m

wnormfit

PURPOSE ^

Parameter estimates for Normal data.

SYNOPSIS ^

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

DESCRIPTION ^

 WNORMFIT Parameter estimates for Normal data.
 
  CALL:  [phat var] = wnormfit(data, plotflag)
 
    phat  = [m, v] = maximum likelihood estimate of the parameters of
            the distribution (see wnormpdf)
    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=wnormrnd(12,2,100,2);
    [phat, var]=wnormfit(R)
 
  See also  wnormpdf

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [phat, var,ciL,ciU] = wnormfit(data,plotflag)
002 %WNORMFIT Parameter estimates for Normal data.
003 %
004 % CALL:  [phat var] = wnormfit(data, plotflag)
005 %
006 %   phat  = [m, v] = maximum likelihood estimate of the parameters of
007 %           the distribution (see wnormpdf)
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=wnormrnd(12,2,100,2);
016 %   [phat, var]=wnormfit(R)
017 %
018 % See also  wnormpdf
019 
020 %tested on: matlab 5.x
021 % History:
022 % revised pab 24.10.2000
023 % - added  nargchk
024 % - cov changed to var = variance since cov(m,v)=0
025 % - fixed some bugs when data is a matrix 
026 % added ms 15.08.2000
027 
028 error(nargchk(1,2,nargin))
029 if nargin<2|isempty(plotflag),  plotflag=1; end
030 sz = size(data);
031 Nsz=length(sz);
032 dim = min(find(sz~=1));  %1st non-singleton dimension
033 % make sure dim=1 is the first non-singleton dimension
034 if isempty(dim) | dim ~= 1, 
035   order = [dim 1:dim-1 dim+1:Nsz];
036   data  = permute(data,order);
037   sz    = size(data);
038 end
039 m = prod(sz(2:end));
040 n =sz(1);
041 
042 mhat=mean(data);
043 vhat=std(data).^2;
044 phat=[mhat(:),vhat(:)];
045 
046 var=[vhat(:), 2*vhat(:).^2]/n;
047 if nargout>2, 
048   alpha2=ones(1,2)*0.05/2;
049   tcrit = wtinv([alpha2 1-alpha2],n-1);
050   chi2crit = wchi2inv([alpha2 1-alpha2],n-1);
051   ciL = [(mhat + tcrit(1)*sqrt(vhat/n)), sqrt(vhat*(n-1)./chi2crit(2))];
052   ciU = [(mhat + tcrit(2)*sqrt(vhat/n)), sqrt(vhat*(n-1)./chi2crit(1))];
053   %ciL = wnorminv(alpha2(ones(m,1),:),phat,var);
054   %ciU = wnorminv(1-alpha2(ones(m,1),:),phat,var);
055 end
056 
057 if plotflag 
058   sd=sort(data);
059   empdistr(sd(:,1),[sd(:,1),wnormcdf(sd(:,1),mhat(1),vhat(1))],plotflag ), hold on
060   for ix=2:m,empdistr(sd(:,ix),[sd(:,ix),wnormcdf(sd(:,ix),mhat(ix),vhat(ix))],plotflag),end
061    hold off
062  
063   title([deblank(['Empirical and Normal estimated cdf'])])
064 end
065 
066 
067 
068 
069

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