Home > wafo > wstats > mdist2dcdfplot.m

mdist2dcdfplot

PURPOSE ^

Plot conditional empirical CDF of X1 given X2=x2

SYNOPSIS ^

mdist2dcdfplot(V,H,varargin)

DESCRIPTION ^

 MDIST2DCDFPLOT Plot conditional empirical CDF of X1 given X2=x2
                and optionally compares it with distribution defined
                by the parameter vector phat.
   
   CALL: mdist2dcdfplot(x1,x2,phat,res,plotflag,figdata,sym);
  
        x1,x2 = data
        phat  =  parameter structure array
        res   = resolution (default range(x2)/12)
     plotflag = 0  no plotting
                1 plot cdf F(x1|x2)                  (default)
                2 plot 1-F(x1|x2) on a semilog y-scale 
                3 plot F(x1|x2) 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--'})
   
   MDIST2DCDFPLOT plots the  empirical CDF of X1 given X2 or 
   X2 given X1 and compares it a 2D Weibull distribution with parameters
   given by phat.
  
  NOTE:  SYM can be given anywhere after X1 and X2
  
  Example:
   R = wraylrnd(2,1000,2); x1 = linspace(0,10)';
   phat.x={2 2 .5}; phat.dist={'rayl','rayl'};
   mdist2dcdfplot(R(:,1),R(:,2),phat,[],2,[3 3 1],{'k-','g-'});
 
   See also  mdist2dcdf, empdistr

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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

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