Debian Codegraph @

contrib/ms-sbvar/TZcode/MatlabFiles/mtpdf.m

raw
1 function y = mtpdf(x,xm,C,v,constIx)
2 % y = mtpdf(x,xm,C,v)
3 % The pdf value for multivariate Student t distribution
4 %
5 % x: p-by-draws matrix of values evaluated at where p=size(x,1) is # of variables
6 % xm: p-by-draws matrix of the mean of x
7 % C: p-by-p Choleski square root of PDS S, which is the covariance matrix
8 % in the normal case so that S = C*C'
9 % v (>0): scaler -- the degrees of freedom
10 % constIx: index for the constant. 1: constant (normalized); 0: no constant (unnormalized)
11 %----------
12 % y: p-by-draws matrix of pdf's for multivariate Student t distribution with v degrees of freedom
13 %
14 % Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994,
15 % p. 382.
16 %
17 % December 1998 by Tao Zha
18 %
19 % Copyright (C) 1997-2012 Tao Zha
20 %
21 % This free software: you can redistribute it and/or modify
22 % it under the terms of the GNU General Public License as published by
23 % the Free Software Foundation, either version 3 of the License, or
24 % (at your option) any later version.
25 %
26 % It is distributed in the hope that it will be useful,
27 % but WITHOUT ANY WARRANTY; without even the implied warranty of
28 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 % GNU General Public License for more details.
30 %
31 % If you did not received a copy of the GNU General Public License
32 % with this software, see <http://www.gnu.org/licenses/>.
33 %
34
35 [p,nx]=size(x);
36 z = C\(x-xm);
37
38
39 if constIx
40 dSh=sum(log(diag(C))); % (detSigma)^(1/2)
41 %* Use gammaln function to avoid overflows.
42 term = exp(gammaln((v + p) / 2) - gammaln(v/2) - dSh);
43 y = (term*(v*pi)^(-p/2)) * (1 + sum(z.*z,1)/v).^(-(v + p)/2);
44 y = y';
45 else
46 y = (1 + sum(z.*z,1)/v).^(-(v + p)/2);
47 y = y';
48 end