MDIST2DSTATPLOT Computes and plots the conditional mean and standard deviation. CALL: mdist2dstatplot(x1,x2,phat,condon,res); x1,x2 = data phat = parameter structure array 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) MDIST2DSTATPLOT plots the empirical conditional mean and standard deviation of X1 given X2 or X2 given X1 and compares it with theoretical quantities. Example: x1=linspace(0,10)'; phat.x={1 2 2 }; phat.dist={'rayl','rayl'}; [y1,y2] = mdist2drnd(2000,phat); mdist2dstatplot(y1,y2,phat,2); See also mdist2dstat
Mean and variance for the MDIST2D distribution. | |
Calculates the difference between the maximum and minimum values. | |
Create axes in arbitrary positions. | |
Display message and abort function. | |
Hold current graph. | |
Linearly spaced vector. | |
Average or mean value. | |
Not-a-Number. | |
Linear plot. | |
Graphs with y tick labels on the left and right. | |
Set object properties. | |
Standard deviation. | |
Graph title. | |
X-axis label. |
001 function [ax11, h11, h22 ]=mdist2dstatplot(V,H,phat,condon ,res) 002 %MDIST2DSTATPLOT Computes and plots the conditional mean and standard deviation. 003 % 004 % CALL: mdist2dstatplot(x1,x2,phat,condon,res); 005 % 006 % x1,x2 = data 007 % phat = parameter structure array 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 % 012 % 013 % MDIST2DSTATPLOT plots the empirical conditional mean and standard deviation of 014 % X1 given X2 or X2 given X1 and compares it with theoretical quantities. 015 % 016 % Example: 017 % x1=linspace(0,10)'; 018 % phat.x={1 2 2 }; 019 % phat.dist={'rayl','rayl'}; 020 % [y1,y2] = mdist2drnd(2000,phat); 021 % mdist2dstatplot(y1,y2,phat,2); 022 % 023 % See also mdist2dstat 024 025 026 % tested on: matlab 5.2 027 % history 028 % revised pab 03.11.2000 029 % changed var(tmp) to std(tmp)^2 030 % revised pab 8.11.1999 031 % - updated header info 032 % - changed phat from vector to structure 033 % by Per A. Brodtkorb 31.01.99 034 035 036 error(nargchk(3,5,nargin)) 037 038 if nargin <4 |isempty(condon), condon =2; end 039 040 if nargin<5|isempty(res), 041 if condon==2, 042 res=range(H(:))/12; 043 else 044 res=range(V(:))/12; 045 end 046 end 047 048 049 Nmesh=40; 050 if condon==2, 051 grp=floor(H/res)+1; % dividing the data into groups 052 Ngrp=max(grp); 053 cvar=linspace(eps, max(H), Nmesh)'; 054 [m v ]=findmeancovar(V,grp); 055 else 056 grp=floor(V/res)+1; % dividing the data into groups 057 Ngrp=max(grp); 058 cvar=linspace(eps, max(V), Nmesh)'; 059 [m v ]=findmeancovar(H,grp); 060 end 061 062 h1=linspace(res/2, (Ngrp-0.5)*res, Ngrp)'; 063 [M1 V1]= mdist2dstat(phat,condon,cvar); 064 065 066 if 0, 067 [ax1 h11 h22]=plotyy(h1,m,h1,sqrt(v)); 068 set(ax1(1),'nextplot','add' ); 069 set(h11, 'LineStyle' , 'x') 070 axes(ax1(1)); 071 plot(cvar,M1,'-'), 072 set(ax1(1),'nextplot','replace' ); 073 074 set(ax1(2),'nextplot','add' ); 075 set(h22, 'LineStyle' , 'o') 076 axes(ax1(2)); 077 %axis([0 inf 0 max(v)]) 078 079 plot(cvar,sqrt(V1),'-'), 080 set(ax1(2),'nextplot','replace' ); 081 else 082 plot(h1,m,'bo',h1,sqrt(v),'rx'); hold on 083 plot(cvar,M1,'b-'), 084 plot(cvar,sqrt(V1),'r--'),hold off 085 end 086 if condon ==2 087 xlabel('x2') 088 else 089 xlabel('x1') 090 end 091 title('Conditional mean and standard deviation') 092 if nargout>0 093 ax11=ax1; 094 end 095 096 097 function [m, v ]=findmeancovar(V,grp) 098 099 Ngrp=max(grp); 100 m=zeros(Ngrp,1);v=m; 101 for ix=1:Ngrp, 102 tmp=V(grp==ix);%find data in group number ix 103 104 if length(tmp)>max(4,0),% if less than 4 observations in the group 105 m(ix)=mean(tmp); % mean of data in group ix 106 v(ix)=std(tmp).^2; % variance of data in group ix 107 else 108 m(ix)=NaN; 109 v(ix)=NaN; 110 end 111 end 112 return 113
Comments or corrections to the WAFO group