Home > wafo > wstats > wchi2cdf.m

# wchi2cdf

## PURPOSE

Chi squared cumulative distribution function

## SYNOPSIS

F = wchi2cdf(x,p);

## DESCRIPTION

``` WCHI2CDF Chi squared cumulative distribution function

CALL:  F = wchi2cdf(x,p);

F = distribution function evaluated at x
p = degrees of freedom

The Chi squared distribution is defined by its pdf

f(x)=x^(p/2-1)*exp(-x/2)/gamma(p/2)/2^(p/2), x>=0, p=1,2,3,...

Example:
x = linspace(0,15,200);
p1 = wchi2cdf(x,2); p2 = wchi2cdf(x,3);
plot(x,p1,x,p2)```

## 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. gammainc Incomplete gamma function. nan Not-a-Number. warning Display warning message; disable or enable warning messages.
This function is called by:
 chi2gof CHI Squared Goodness Of Fit test. chi2gof2 CHI Squared Goodness Of Fit test. wchi2fit Parameter estimates for Chi squared data.

## SOURCE CODE

```001 function F = wchi2cdf(x,p);
002 %WCHI2CDF Chi squared cumulative distribution function
003 %
004 % CALL:  F = wchi2cdf(x,p);
005 %
006 %        F = distribution function evaluated at x
007 %        p = degrees of freedom
008 %
009 % The Chi squared distribution is defined by its pdf
010 %
011 %   f(x)=x^(p/2-1)*exp(-x/2)/gamma(p/2)/2^(p/2), x>=0, p=1,2,3,...
012 %
013 % Example:
014 %   x = linspace(0,15,200);
015 %   p1 = wchi2cdf(x,2); p2 = wchi2cdf(x,3);
016 %   plot(x,p1,x,p2)
017
018 % Reference: Johnson, Kotz and Balakrishnan (1994)
019 % "Continuous Univariate Distributions, vol. 1", p. 415 ff
020 % Wiley
021
022 % Tested on; Matlab 5.3
023 % History:
024 % revised pab 25.10.2000
025 %  - added comnsize, nargchk
027
028 error(nargchk(2,2,nargin))
029 [errorcode,x,p] = comnsize(x,p);
030 if errorcode > 0
031   error('x and p must be of common size or scalar.');
032 end
033
034
035 % old call
036 %F= gammainc(x/2,p/2).*(x>=0);
037 F = zeros(size(x));
038 ok= ((p >0)& p==round(p) );
039
040 k=find(x > 0 & ok);
041 if any(k),
042   F(k)= gammainc(x(k)/2,p(k)/2);
043 end
044
045 %   Return NaN if the arguments are outside their respective limits.
046 k3 = find(~ok);
047 if any(k3)
048   warning('p should be a positive integer')
049   tmp = NaN;
050   F(k3) = tmp(ones(size(k3)));
051 end
052
053```

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