Home > wafo > wstats > wgamstat.m

# wgamstat

## PURPOSE

Mean and variance for the Gamma distribution.

## SYNOPSIS

[m,v]= wgamstat(a,b);

## DESCRIPTION

``` WGAMSTAT Mean and variance for the Gamma distribution.

CALL:  [m,v] = wgamstat(a,b)

m, v = the mean and variance, respectively
a = parameter, a>0
b = parameter, b>0 (default b=1)

Mean (m) and variance (v) for the Gamma distribution is

m=ab  and  v=ab^2;

Example:
[m,v] = wgamstat(5,2)```

## CROSS-REFERENCE INFORMATION

This function calls:
 comnsize Check if all input arguments are either scalar or of common size. error Display message and abort function. nan Not-a-Number.
This function is called by:
 dist2dcdf Joint 2D CDF computed as int F(X1 dist2dstat Mean and variance for the DIST2D distribution mdist2dstat Mean and variance for the MDIST2D distribution.

## SOURCE CODE

```001 function [m,v]= wgamstat(a,b);
002 %WGAMSTAT Mean and variance for the Gamma distribution.
003 %
004 % CALL:  [m,v] = wgamstat(a,b)
005 %
006 %   m, v = the mean and variance, respectively
007 %      a = parameter, a>0
008 %      b = parameter, b>0 (default b=1)
009 %
010 %  Mean (m) and variance (v) for the Gamma distribution is
011 %
012 %  m=ab  and  v=ab^2;
013 %
014 % Example:
015 %   [m,v] = wgamstat(5,2)
016
017 % Reference: Johnson, Kotz and Balakrishnan (1994)
018 % "Continuous Univariate Distributions, vol. 1", p. 494 ff
019 % Wiley
020
021 % Tested on; Matlab 5.3
022 % History:
023 % revised pab Dec2003
024 % fixed a bug: k1 -> k3
025 % revised pab 24.10.2000
026 %  - added comnsize, nargchk
027 % added ms 26.06.2000
028 % added b parameter ms 23.08.2000
029
030 error(nargchk(1,2,nargin))
031 if nargin<2,  b=1;end
032 [errorcode a b] = comnsize(a,b);
033 if errorcode > 0
034     error('a and b must be of common size or scalar.');
035 end
036
037 % Initialize  m  and v to zero.
038 m = zeros(size(a));
039 v=m;
040
041 k=find(a > 0 & b>0);
042 if any(k),
043   m(k) =  a(k).*b(k);
044   v(k) = m(k).*b(k);
045 end
046
047 k3 = find(a<=0 | b<=0 );
048 if any(k3)
049   tmp = NaN;
050   m(k3) = tmp(ones(size(k3)));
051   v(k3)=m(k3);
052 end
053
054
055
056```

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