Home > wafo > wstats > wchi2pdf.m

wchi2pdf

PURPOSE ^

Chi squared probability density function

SYNOPSIS ^

f = wchi2pdf(x,p,disable);

DESCRIPTION ^

 WCHI2PDF Chi squared probability density function
 
  CALL:  f = wchi2pdf(x,p);
 
         f = density 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,...
  The CHI^2 is a special case of the gamma distribution, i.e.:
    wchi2pdf(x,p)=wgampdf(x,p/2,2)
 
  Example: 
  x = linspace(0,7,200);
  p1 = wchi2pdf(x,2); p2 = wchi2pdf(x,3);
  plot(x,p1,x,p2)
 
  See also wgampdf

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function f = wchi2pdf(x,p,disable);
002 %WCHI2PDF Chi squared probability density function
003 %
004 % CALL:  f = wchi2pdf(x,p);
005 %
006 %        f = density function evaluated at x
007 %        p = degrees of freedom
008 % 
009 % The Chi squared distribution is defined by its pdf
010 %   f(x)=x^(p/2-1)*exp(-x/2)/gamma(p/2)/2^(p/2), x>=0, p=1,2,3,...
011 % The CHI^2 is a special case of the gamma distribution, i.e.:
012 %   wchi2pdf(x,p)=wgampdf(x,p/2,2)
013 %
014 % Example: 
015 % x = linspace(0,7,200);
016 % p1 = wchi2pdf(x,2); p2 = wchi2pdf(x,3);
017 % plot(x,p1,x,p2)
018 %
019 % See also wgampdf
020 
021 % Reference: Johnson, Kotz and Balakrishnan (1994)
022 % "Continuous Univariate Distributions, vol. 1", p. 415 ff
023 % Wiley
024 
025 
026 % Tested on: Matlab 5.3
027 % History:
028 % revised pab 25.10.2000
029 %  - added comnsize, nargchk
030 %  - replaced code with a call to wggampdf -> made maintanence easier
031 % added ms 15.06.2000
032 
033 
034 error(nargchk(2,3,nargin))
035 % secret option in order to make ML estimation work
036 if nargin<3|isempty(disable), disable=0;end 
037 
038 [errorcode,x,p,b,c] = comnsize(x,p,2,1);
039 if errorcode > 0
040   error('x and p must be of common size or scalar.');
041 end
042 
043 f=zeros(size(x));
044 if disable,
045   ok = (p>0);
046 else
047   ok = (p==round(p) & p>0)
048 end
049 k = find(ok);
050 if any(k),
051   f(k) = wggampdf(x(k),p(k)/2,b(k),c(k));
052   %f=x.^(p/2-1).*exp(-x/2)/gamma(p/2)/2^(p/2).*(x>=0);
053 end
054 
055 k1=find(~ok);
056 if any(k1),
057   warning('p should be a positive integer')
058   f(k1)=NaN;
059 end
060 
061 
062 
063 
064 
065 
066

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