Home > wafo > wstats > dist2dstatplot.m

dist2dstatplot

PURPOSE ^

Computes and plots the conditional mean and standard deviation

SYNOPSIS ^

[ax11, h11, h22 ]=dist2dstatplot(V,H,varargin)

DESCRIPTION ^

  DIST2DSTATPLOT Computes and plots the conditional mean and standard deviation
  
    CALL: dist2dstatplot(x1,x2,phat,condon,res,csm,lin,sym);
 
       x1,x2 = data
       phat  =  parameter structure array (see dist2dfit)
     condon  = 1 mean and standard deviation of X2 given X1
               2 mean and standard deviation of X1 given X2 (default)
       res   = resolution (default range(x2)/12)
       csm   = smoothing vector     (default [1 1 1])
       lin   = extrapolation vector (default [1 1 1])
       sym   = {s1,s2,s3,s4} cell array of plot symbols for 
               plotting empirical mean and standard deviation and 
               theoretical mean and standard deviation, respectively.
               (default {'bo','rx','b-','r--'})
 
  DIST2DSTATPLOT plots the  empirical conditional mean and standard
  deviation of X1 given X2 or X2 given X1 and optionally compares it with
  theoretical quantities.
 
  NOTE:  SYM can be given anywhere after X1 and X2.
 
  Example:
   x1=linspace(0,10)';
   phat.x={[x1,exp(-0.1*x1)] 2 };
   phat.dist={'rayl','rayl'};
   [y1,y2] = dist2drnd(1000,phat);
   dist2dstatplot(y1,y2,phat,2);
 
  See also  dist2dstat

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function [ax11, h11, h22  ]=dist2dstatplot(V,H,varargin) 
002 % DIST2DSTATPLOT Computes and plots the conditional mean and standard deviation
003 % 
004 %   CALL: dist2dstatplot(x1,x2,phat,condon,res,csm,lin,sym);
005 %
006 %      x1,x2 = data
007 %      phat  =  parameter structure array (see dist2dfit)
008 %    condon  = 1 mean and standard deviation of X2 given X1
009 %              2 mean and standard deviation of X1 given X2 (default)
010 %      res   = resolution (default range(x2)/12)
011 %      csm   = smoothing vector     (default [1 1 1])
012 %      lin   = extrapolation vector (default [1 1 1])
013 %      sym   = {s1,s2,s3,s4} cell array of plot symbols for 
014 %              plotting empirical mean and standard deviation and 
015 %              theoretical mean and standard deviation, respectively.
016 %              (default {'bo','rx','b-','r--'})
017 %
018 % DIST2DSTATPLOT plots the  empirical conditional mean and standard
019 % deviation of X1 given X2 or X2 given X1 and optionally compares it with
020 % theoretical quantities.
021 %
022 % NOTE:  SYM can be given anywhere after X1 and X2.
023 %
024 % Example:
025 %  x1=linspace(0,10)';
026 %  phat.x={[x1,exp(-0.1*x1)] 2 };
027 %  phat.dist={'rayl','rayl'};
028 %  [y1,y2] = dist2drnd(1000,phat);
029 %  dist2dstatplot(y1,y2,phat,2);
030 %
031 % See also  dist2dstat
032  
033 %tested on: matlab 5.2
034 % history:
035 % revised pab 03.11.2000
036 % - replaced call to var with std(tmp)^2
037 % revised pab 22.06.2000
038 %  - added varargin
039 %  - fixed some bugs for condon ==1
040 %  - added sym 
041 %  - fixed a bug for res.
042 %  - updated header for csm and lin
043 % by Per A. Brodtkorb 23.11.98
044 
045 
046 if  nargin<2,  error('Two input arguments required'), end 
047 
048 % default values
049 %~~~~~~~~~~~~~~~
050 sym = {'bo','rx','b-','r--'}; % default plot symbols for the empirical
051                               % mean and std, and theoretical mean and std,respectively
052 phat =[];
053 lin    = [1 1 1]; 
054 csm    = [1 1 1];
055 res    = [];
056 condon = 2; 
057 
058 
059 if 1,%new call
060   P  = varargin;
061   Np = length(P);
062   if Np>0
063     strix = zeros(1,Np);
064     cellix = strix;
065     for ix=1:Np, % finding symbol strings or cell array of symbol strings
066       strix(ix)  = ischar(P{ix});
067       cellix(ix) = iscell(P{ix});
068     end
069     k  = find(strix);
070     k1 = find(cellix);
071     if any(k)
072       Nk = length(k);
073       if Nk>4,  warning('More than 4 strings are not allowed'),    end
074       iy = 1;
075       for ix=k      
076     sym{iy} = P{ix};
077     iy=iy+1;
078       end
079       Np = Np-Nk;
080       P  = {P{find(~strix)}}; % remove strings from input
081     elseif any(k1) % cell array of strings
082       tmp = P{k1};
083       Nk = length(tmp);
084       if Nk>4,  warning('More than 4 strings are not allowed'),    end
085       iy = 1;
086       for ix=1:min(Nk,4)
087     if ~isempty(tmp{ix}) & ischar(tmp{ix}), sym{ix}=tmp{ix};end
088       end
089       Np = Np-1;
090       P  = {P{find(~cellix)}}; % remove cell array of strings from input
091     end
092     if Np>0 & ~isempty(P{1}), phat   = P{1};end
093     if Np>1 & ~isempty(P{2}), condon = P{2};end
094     if Np>2 & ~isempty(P{3}), res    = P{3};end
095     if Np>3 & ~isempty(P{4}), csm    = P{4};end
096     if Np>4 & ~isempty(P{5}), lin    = P{5};end
097   end
098 else % old call
099   %function [ax11, h11, h22  ]=dist2dstatplot(V,H,phat,condon ,res,csm,lin)
100   if (nargin<7)|isempty(lin),    lin    = [1 1 1];  end
101   if (nargin<6)|isempty(csm),    csm    = [1 1 1];  end
102   if (nargin<5)|isempty(res),    res    = range(H(:))/12; end
103   if (nargin<4)|isempty(condon), condon = 2; end
104 end
105 
106 if isempty(res)
107   if condon==1,    res = range(V(:))/12;  else    res = range(H(:))/12;  end
108 end
109 
110 
111 if condon==2,
112   grp=floor(H/res)+1; % dividing the data into groups 
113   xmax = max(H);
114   Xc = V;         
115 else
116   grp=floor(V/res)+1; % dividing the data into groups 
117   xmax = max(V)
118   Xc = H;
119 end
120 
121 Ngrp  = max(grp);
122 Nmesh = 40;
123 h1    = linspace(res/2, (Ngrp-0.5)*res, Ngrp)';
124 
125 
126 
127 %cvar=linspace(eps,max(V),Nmesh)';
128 if ~isempty(phat), % theoretical distribution not given
129   cvar  = linspace(0, xmax, Nmesh)';
130   [M1 V1] = dist2dstat(phat,condon,cvar,csm,lin);
131 end
132 
133 m=h1;v=h1;
134 for ix=1:Ngrp,
135   tmp = Xc(grp==ix);%find data in group number ix
136   
137   if length(tmp)>max(4,0),% if less than 4 observations in the group 
138     m(ix)=mean(tmp); % mean of data in group ix
139     v(ix)=std(tmp).^2;  % variance of data in group ix
140   else 
141     m(ix)=NaN;
142     v(ix)=NaN;
143   end
144 end
145 
146 if 0,
147   [ax1 h11 h22]=plotyy(h1,m,h1,sqrt(v));
148   set(ax1(1),'nextplot','add' );
149   set(h11, 'LineStyle' , 'x')
150   axes(ax1(1));
151   plot(cvar,M1,'-'),
152   set(ax1(1),'nextplot','replace' );
153   
154   set(ax1(2),'nextplot','add' );
155   set(h22, 'LineStyle' , 'o')
156   axes(ax1(2));
157   %axis([0 inf 0 max(v)])
158   
159   plot(cvar,sqrt(V1),'-'), 
160   set(ax1(2),'nextplot','replace' );
161 else
162   ih = ishold;
163   plot(h1,m,sym{1},h1,sqrt(v),sym{2});  hold on
164   
165   if ~isempty(phat),    plot(cvar,M1,sym{3},cvar,sqrt(V1),sym{4}),  end
166   
167   if ~ih, hold off,end
168 end
169 
170 xlabel(['x' num2str(condon)])
171 
172 title('Conditional mean and standard deviation')
173 if nargout>0
174   ax11=ax1;
175 end
176

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