Home > wafo > wstats > wtpdf.m

wtpdf

PURPOSE ^

Student's T probability density function

SYNOPSIS ^

f = wtpdf(x,df,disable)

DESCRIPTION ^

 WTPDF  Student's T probability density function
 
  CALL:  f = wtpdf(x,df)
 
    f = density function evaluated at x
    x = matrix
    df = degrees of freedom (1,2,....)
 
  Example:
    x = linspace(-5,5,200);
    p1 = wtpdf(x,1); p2 = wtpdf(x,5);
    plot(x,p1,x,p2)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function f = wtpdf(x,df,disable)
002 %WTPDF  Student's T probability density function
003 %
004 % CALL:  f = wtpdf(x,df)
005 %
006 %   f = density function evaluated at x
007 %   x = matrix
008 %   df = degrees of freedom (1,2,....)
009 %
010 % Example:
011 %   x = linspace(-5,5,200);
012 %   p1 = wtpdf(x,1); p2 = wtpdf(x,5);
013 %   plot(x,p1,x,p2)
014 
015 % tested on matlab 5.3
016 %History:
017 %revised pab 29.10.2000
018 % adapted from stixbox changed name to wtpdf
019 % -added nargchk + check on floor(df)==df
020 % - changed from gamma to gammaln for more stable computation
021 % - added the secret option disable in order to use this function for MLE
022 %   estimation 
023 %  by Anders Holtsberg, 18-11-93
024 %     Copyright (c) Anders Holtsberg
025 
026 error(nargchk(2,3,nargin))
027 [errorcode x,df]=comnsize(x,df);
028 if errorcode>0,
029   error('x and df must be of common size or scalar');
030 end
031 if nargin<3|isempty(disable), disable=0;end
032 
033 f=zeros(size(x));
034 mxdf=10^7;
035 
036 if disable,
037   ok = (0<df); % disable check on df
038 else
039   ok = (0<df & df==floor(df));
040 end
041 k=find(ok & df<mxdf);
042 if any(k), % use gammaln for more stable computation for large df
043   tmp = exp(gammaln((df(k)+1)/2)-gammaln(df(k)/2))./sqrt(df(k));
044   f(k) = tmp./sqrt(pi).*(1+x(k).^2./df(k)).^(-(df(k)+1)/2);  
045 end
046 
047 
048 k1=find(ok & df>mxdf);
049 if any(k1)
050   f(k1)=wnormpdf(x(k1),0,1);
051 end
052   
053 k2 = find(~ok);
054 if any(k2)
055   f(k2)=NaN;
056 end
057

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