Home > wafo > wstats > dist2dstat.m

# dist2dstat

## PURPOSE

Mean and variance for the DIST2D distribution

## SYNOPSIS

[M,V, eps2, a ,b] = dist2dstat(phat,condon,cvar,csm,lin)

## DESCRIPTION

```  DIST2DSTAT  Mean and variance for the DIST2D distribution

CALL:  [M,V] = dist2dstat(phat,condon,cvar,csm,lin)

M,V    = mean and variance, respectively
phat   = parameter structure array (see dist2dfit)
condon = 0 returns marginal mean and variance for X1, X2 (default)
1 returns conditional mean and variance of X2 given X1
2 returns conditional mean and variance of X1 given X2
cvar  = conditional variable, i.e.,x1 or x2 depending on condon.
csm   = smoothing vector (see dist2dsmfun) (default [1 1 1])
lin   = extrapolation vector (default [1 1 1])

Example:
x1=linspace(0,10)';
phat.x={[x1,exp(-0.1*x1)] 2 };
phat.dist={'rayl','rayl'};
[M,V]=dist2dstat(phat,2,x1);
plot(x1,M,'r--',x1,sqrt(V),'k-')
title(' Conditional mean and standard deviation')
legend('E(x1|x2)','std(x1|x2)')
xlabel('x2')

## CROSS-REFERENCE INFORMATION

This function calls:
 dist2dsmfun Smooths the conditional DIST2D distribution parameters. wgamstat Mean and variance for the Gamma distribution. wgumbstat Mean and variance for the Gumbel distribution. wlognstat Mean and variance for the Lognormal distribution. wraylstat Mean and variance for the Rayleigh distribution. wweibstat Mean and variance for the Weibull distribution. error Display message and abort function. linspace Linearly spaced vector. lower Convert string to lowercase.
This function is called by:
 dist2dstatplot Computes and plots the conditional mean and standard deviation

## SOURCE CODE

```001 function [M,V, eps2, a ,b] = dist2dstat(phat,condon,cvar,csm,lin)
002 % DIST2DSTAT  Mean and variance for the DIST2D distribution
003 %
004 %  CALL:  [M,V] = dist2dstat(phat,condon,cvar,csm,lin)
005 %
006 %    M,V    = mean and variance, respectively
007 %    phat   = parameter structure array (see dist2dfit)
008 %    condon = 0 returns marginal mean and variance for X1, X2 (default)
009 %             1 returns conditional mean and variance of X2 given X1
010 %             2 returns conditional mean and variance of X1 given X2
011 %     cvar  = conditional variable, i.e.,x1 or x2 depending on condon.
012 %     csm   = smoothing vector (see dist2dsmfun) (default [1 1 1])
013 %     lin   = extrapolation vector (default [1 1 1])
014 %
015 % Example:
016 %  x1=linspace(0,10)';
017 %  phat.x={[x1,exp(-0.1*x1)] 2 };
018 %  phat.dist={'rayl','rayl'};
019 %  [M,V]=dist2dstat(phat,2,x1);
020 %  plot(x1,M,'r--',x1,sqrt(V),'k-')
021 %  title(' Conditional mean and standard deviation')
022 %  legend('E(x1|x2)','std(x1|x2)')
023 %  xlabel('x2')
024 %
026
027 %tested on: matlab 5.2
028 % history:
029 %  by Per A. Brodtkorb 28.10.98
030
031 if (nargin< 4)|isempty(csm),
032   csm=[];
033 end
034
035 if (nargin< 5)|isempty(lin),
036   lin=[];
037 end
038 if nargin<3|isempty(cvar) ,
039   cvar=[];
040 end
041
042 if (nargin <2) |  isempty(condon),
043  condon=0;
044 end
045 if (condon~=0 )&(nargin ==0),
046   error('Requires one input argument the levels to condition on.');
047 end
048
049 UDIST=lower(phat.dist{2});
050 CDIST=lower(phat.dist{1});
051 PH=phat.x{2};
052
053
054 switch UDIST(1:2)
055   case 'ra',  [m2,v2]= wraylstat(PH(1));
056   case 'we' ,  [m2,v2]=wweibstat(PH(1),PH(2));
057   case 'gu' ,  [m2,v2]=wgumbstat(PH(1),PH(2),0);
058   case 'tg' ,  [m2,v2]=wgumbstat(PH(1),PH(2),1);
059   case 'ga' ,  [m2,v2]=wgamstat(PH(1),PH(2));
060   case 'lo' ,  [m2,v2]=wlognstat(PH(1),PH(2));
061   otherwise, error('unknown distribution')
062 end
063
064 switch condon, %marginal stats
065   case 0,
066     M=zeros(1,2); %initialize mean
067     V=M;%initialize variance
068    M(2)=m2; V(2,2)=v2;
069    disp('Warning this option is not complete!')
070    %    M(1)=m1; V(1,1)=v1;
071    % v(1,2)=covar; M2,1)=covar;
072
073  case 1 , % conditional stats given V
074       M=zeros(size(cvar)); %initialize mean
075       V=M;%initialize variance
076       error('not implemented yet!')
077       switch UDIST(1:2) % this is not correct yet
078     case 'ra',  pdf1= wraylstat(PH);
079     case 'we' ,  pdf1=wweibstat(PH(1),PH(2));
080     case 'gu' ,  pdf1=wgumbstat(PH(1),PH(2),0);
081     case 'tg' ,  pdf1=wgumbstat(PH(1),PH(2),1);
082     case 'ga' ,  pdf1=wgamstat(PH(1),PH(2));
083     case 'lo' ,  pdf1=wlognstat(PH(1),PH(2));
084     otherwise, error('unknown distribution')
085       end
086     case 2, % conditional stats given H
087
088       if isempty(cvar),cvar=linspace(0 ,m2+3*sqrt(v2),30)'; end
089       M=zeros(size(cvar)); %initialize mean
090       V=M;%initialize variance
091       %size(cvar)
092       [Av , Bv, Cv]=dist2dsmfun(phat,cvar,csm,lin);
093       switch CDIST(1:2)
094     case 'ra', [M,V] =  wraylstat(Av);
095     case 'gu', [M,V] =  wgumbstat(Av,Bv,0);
096     case 'tg', [M,V] =  wgumbstat(Av,Bv,1);
097     case 'lo', [M,V] =  wlognstat(Av,Bv);
098     case 'ga', [M,V] =  wgamstat(Av,Bv);
099     case 'we', [M,V] =  wweibstat(Av,Bv);
100     otherwise, error('Unknown distribution')
101       end
102
103     otherwise error('Unkown value for condon')
104   end
105 M=M+Cv;
106
107
108
109```

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