WTFIT Parameter estimates for Student's T data. CALL: [phat, var] = wtfit(data, plotflag) phat = [df] = the maximum likelihood estimate of the parameter of the T distribution 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=wtrnd(2,1,100); phat = wtfit(R,2) See also wtcdf, empdistr
Computes and plots the empirical CDF | |
Log-likelihood function. | |
Inverse of the Normal distribution function | |
Student's T cumulative distribution function | |
Remove trailing blanks. | |
Display message and abort function. | |
Multidimensional unconstrained nonlinear minimization (Nelder-Mead). | |
Create/alter OPTIM OPTIONS structure. | |
Standard deviation. | |
Convert string matrix to numeric array. | |
Graph title. | |
MATLAB version number. |
001 function [phat, cov,pci]=wtfit(data1, plotflag); 002 %WTFIT Parameter estimates for Student's T data. 003 % 004 % CALL: [phat, var] = wtfit(data, plotflag) 005 % 006 % phat = [df] = the maximum likelihood estimate of the 007 % parameter of the T distribution 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=wtrnd(2,1,100); 017 % phat = wtfit(R,2) 018 % 019 % See also wtcdf, 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 sa = std(data)^2; 037 038 % Supply a starting guess with method of moments: 039 phat0 = max(round(2*sa/(sa-1)),1); 040 041 mvrs=version;ix=find(mvrs=='.'); 042 if str2num(mvrs(1:ix(2)-1))>5.2, 043 phat = round(fminsearch('loglike',phat0,optimset,data,1,'wtpdf')); 044 else 045 phat = round(fmins('loglike',phat0,[],[],data,1,'wtpdf')); 046 end 047 048 phat = [phat-1 phat phat+1] +(phat==1); 049 LL(1) = loglike(phat(1),data,'wtpdf'); 050 LL(2) = loglike(phat(2),data,'wtpdf'); 051 LL(3) = loglike(phat(3),data,'wtpdf'); 052 [Y,ind] = min(LL); 053 phat = phat(ind); 054 055 056 if nargout>1, 057 [LL, cov] = loglike(phat,data,'wtpdf'); 058 end 059 if nargout>2 060 alpha2 = ones(1,1)*0.05/2; 061 var = cov; 062 pci = wnorminv([alpha2;1-alpha2], [phat;phat],[var;var]); 063 end 064 065 if plotflag 066 sd = sort(data); 067 empdistr(sd,[sd, wtcdf(sd,phat)],plotflag) 068 title([deblank(['Empirical and Student''s T estimated cdf'])]) 069 end 070
Comments or corrections to the WAFO group