Home > wafo > wstats > dist2dcdfplot.m

dist2dcdfplot

PURPOSE ^

Plot conditional empirical CDF of X1 given X2=x2

SYNOPSIS ^

dist2dcdfplot(V,H,varargin)

DESCRIPTION ^

  DIST2DCDFPLOT Plot conditional empirical CDF of X1 given X2=x2
                and optionally compares it with distribution defined
                by the parameter structure phat.
   
   CALL: dist2dcdfplot(x1,x2,phat,condon,res,plotflag,figdata,sym);
  
        x1,x2 = data
        phat  =  parameter structure array
      condon  = 1 CDF of X2 given X1
                2 CDF of X1 given X2 (default)
        res   = resolution (default range(x2)/12)
     plotflag = 0  no plotting
                1 plot cdf F(z;z>=c)                  (default)
                2 plot 1-F(z;z>=c) on a semilog y-scale 
                3 plot F(z;z>=c) on a log log scale
      figdata = [rows cols Nfig], gives number of rows, columns of which
                each figure is divided into and and the total number of figures.
                (default [3 3 1])
          sym = {s1,s2} cell array of plot symbols for 
                plotting empirical and theoretical cdf, respectively.
                (default {'b.','r--'})
   
   DIST2DCDFPLOT plots the  empirical CDF of X1 given X2 or 
   X2 given X1 and compares it with theoretical quantities.
  
  NOTE:  SYM can be given anywhere after X1 and X2
  
  Example:
   R = wraylrnd(2,1000,2); x1 = linspace(0,10)';
   phat.x={[x1,2*ones(size(x1))] 2 }; phat.dist={'rayl','rayl'};
   dist2dcdfplot(R(:,1),R(:,2),phat,[],[],2,[3 3 1],{'k-','g-'});
 
   See also  dist2dcdf, empdistr

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function dist2dcdfplot(V,H,varargin) 
002 % DIST2DCDFPLOT Plot conditional empirical CDF of X1 given X2=x2
003 %               and optionally compares it with distribution defined
004 %               by the parameter structure phat.
005 %  
006 %  CALL: dist2dcdfplot(x1,x2,phat,condon,res,plotflag,figdata,sym);
007 % 
008 %       x1,x2 = data
009 %       phat  =  parameter structure array
010 %     condon  = 1 CDF of X2 given X1
011 %               2 CDF of X1 given X2 (default)
012 %       res   = resolution (default range(x2)/12)
013 %    plotflag = 0  no plotting
014 %               1 plot cdf F(z;z>=c)                  (default)
015 %               2 plot 1-F(z;z>=c) on a semilog y-scale 
016 %               3 plot F(z;z>=c) on a log log scale
017 %     figdata = [rows cols Nfig], gives number of rows, columns of which
018 %               each figure is divided into and and the total number of figures.
019 %               (default [3 3 1])
020 %         sym = {s1,s2} cell array of plot symbols for 
021 %               plotting empirical and theoretical cdf, respectively.
022 %               (default {'b.','r--'})
023 %  
024 %  DIST2DCDFPLOT plots the  empirical CDF of X1 given X2 or 
025 %  X2 given X1 and compares it with theoretical quantities.
026 % 
027 % NOTE:  SYM can be given anywhere after X1 and X2
028 % 
029 % Example:
030 %  R = wraylrnd(2,1000,2); x1 = linspace(0,10)';
031 %  phat.x={[x1,2*ones(size(x1))] 2 }; phat.dist={'rayl','rayl'};
032 %  dist2dcdfplot(R(:,1),R(:,2),phat,[],[],2,[3 3 1],{'k-','g-'});
033 %
034 %  See also  dist2dcdf, empdistr
035 
036 
037 %  tested on: matlab 5.2
038 % history
039 % revised pab 25.10.2000
040 %  - updated help header
041 % revised pab 23.06.2000
042 %  - added sym and changed input to varargin
043 % revised pab 08.02.2000
044 % -added figdata
045 % revised pab 8.11.1999
046 %  - updated header info
047 %  - changed phat from vector to structure
048 
049 
050 
051 
052 
053 % default values
054 %~~~~~~~~~~~~~~~
055 sym = {[],[]}; % default plot symbols for the empirical
056                               %  theoretical pdf,respectively
057 phat =[];
058 lin    = [1 1 1]; 
059 csm    = [1 1 1];
060 res    = [];
061 condon = 2; 
062 flag   = 1;
063 row=3;col=3;Nfig=1;
064 figdata = [];
065 ih = ishold; % save hold state
066 
067 
068 
069 P  = varargin;
070 Np = length(P);
071 if Np>0
072   strix = zeros(1,Np);
073   cellix = strix;
074   for ix=1:Np, % finding symbol strings or cell array of symbol strings
075     strix(ix)  = ischar(P{ix});
076     cellix(ix) = iscell(P{ix});
077   end
078   k  = find(strix);
079   k1 = find(cellix);
080   if any(k)
081     Nk = length(k);
082     if Nk>2,  warning('More than 2 strings are not allowed'),    end
083     iy = 1;
084     for ix=k      
085       sym{iy} = P{ix};
086       iy=iy+1;
087     end
088     Np = Np-Nk;
089     P  = {P{find(~strix)}}; % remove strings from input
090   elseif any(k1) % cell array of strings
091     tmp = P{k1};
092     Nk = length(tmp);
093     if Nk>2,  warning('More than 2 strings are not allowed'),    end
094     iy = 1;
095     for ix=1:min(Nk,2)
096       if ~isempty(tmp{ix}) & ischar(tmp{ix}), sym{ix}=tmp{ix};end
097     end
098     Np = Np-1;
099     P  = {P{find(~cellix)}}; % remove cell array of strings from input
100   end
101   if Np>0 & ~isempty(P{1}), phat   = P{1};end
102   if Np>1 & ~isempty(P{2}), condon = P{2};end
103   if Np>2 & ~isempty(P{3}), res    = P{3};end
104   if Np>3 & ~isempty(P{4}), flag    = P{4};end
105   if Np>4 & ~isempty(P{5}), figdata = P{5};end
106 end
107 
108 if isempty(res)
109   if condon==1,
110     res=range(V(:))/12;
111   else
112     res=range(H(:))/12;
113   end
114 end
115 
116 if flag<1,  return,end
117 
118 nf=length(figdata);
119 if (nf>0) 
120   if ~isnan(figdata(1)),         row  = figdata(1);end
121   if (nf>1) & ~isnan(figdata(2)),col  = figdata(2);end
122   if (nf>2) & ~isnan(figdata(3)),Nfig = figdata(3);end
123 end
124 
125 Nmesh=40;
126 v1=[];cdfgH=[];
127 if condon==2,
128   
129   Xc      = V;
130   grp     = floor(H/res)+1; % dividing the data into groups 
131   Ngrp    = max(grp);
132   h1      = linspace(res/2, (Ngrp-0.5)*res, Ngrp)';
133   if ~isempty(phat)
134     v1      =linspace(eps,max(V)+range(V)/4,Nmesh);
135     [X1,X2] = meshgrid(v1,h1);
136     cdfgH   = dist2dcdf(X1,X2,phat,condon);
137   end
138   %max(cdfgH')
139   %min(cdfgH')
140   xmax    = max(V);
141  
142 else
143   Xc      = H;
144   grp     = floor(V/res)+1; % dividing the data into groups 
145    Ngrp    = max(grp);
146   h1      = linspace(res/2, (Ngrp-0.5)*res, Ngrp)';
147   if ~isempty(phat)
148     v1      = linspace(eps,max(H)+range(H)/4,Nmesh);
149     [X1,X2] = meshgrid(v1,h1);
150     cdfgH   = dist2dcdf(X2,X1,phat,condon);
151   end
152   xmax    = max(H);
153 end
154 
155 
156 %xmax=min(xmax,4);
157 
158 fignr    = gcf;
159 fignrold = fignr;
160 %figure(fignr)
161 
162 iy=0;
163 for ix=Ngrp:-1:min(grp),
164   if iy==row*col,iy=0; 
165     fignr=fignr+1;
166     if Nfig<=fignr-fignrold, break, end
167     figure(fignr);
168   end
169   tmp = Xc(grp==ix);%find data in group number ix
170   if length(tmp)>max(3,0),% if less than 6 observations in the group 
171     iy=iy+1;
172     subplot(row,col,iy)
173     if ih, hold on, end % make sure we have hold on for each subplot
174     if ~isempty(phat)
175       cempdistr(tmp,0,[v1; cdfgH(ix,:)]',flag,sym)
176     else
177       cempdistr(tmp,0,[],flag,sym)
178     end
179     %grid on
180     
181     axis square
182     Ns = 2;
183     switch  flag,
184       case 1,
185     ylabel(['F(x1|x2=' num2str(h1(ix),Ns) ')'])
186     xlabel('x1')
187     title('')
188     axis([0 ceil(xmax) 0 1])
189     % title(['Cumulative density function v given h=' num2str(h1(ix),3) ])
190       case 2,
191     %figtext(0.1,0.1,['1-F(v| h=' num2str(h1(ix),Ns)  ')'],'norm');
192     ylabel(['1-F(x1|x2=' num2str(h1(ix),Ns)  ')'])
193     xlabel('x1')
194     grid off
195     title('')
196     axis([0 ceil(xmax) 1e-4 1])
197     %  title(['The probability of exceeding v given h=' num2str(h1(ix),3)  ])
198       case 3 ,
199     ylabel(['-log(-log(F(x1|x2=' num2str(h1(ix),Ns)  ')))'])
200     xlabel('x1')
201     title('')
202       case 4,
203     ylabel(['(-log(F(x1|x2=' num2str(h1(ix),Ns)  ')))'])
204     xlabel('x1')
205     title('')
206     %  title(['T
207     end
208     
209     %if printflag, print -Pmhlaser ; end   %print -Pmhlaser
210   end
211 end
212 
213 if ~ih, hold off, end

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