| 1 |
function y = mnpdf(x,xm,C,constIx) |
| 2 |
% y = mnpdf(x,xm,C,constIx) |
| 3 |
% The pdf value for multivariate normal 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 -- the covariance matrix so that S = C*C' |
| 8 |
% constIx: index for the constant. 1: constant (normalized); 0: no constant (unnormalized) |
| 9 |
%---------- |
| 10 |
% y: p-by-draws matrix of pdf's for multivariate normal distribution |
| 11 |
% |
| 12 |
% Christian P. Robert, "The Bayesian Choice," Springer-Verlag, New York, 1994, |
| 13 |
% p. 381. |
| 14 |
% |
| 15 |
% November 1998 by Tao Zha |
| 16 |
% rewritten by CAS 12/98 to take matrix x, return vector y |
| 17 |
% |
| 18 |
% Copyright (C) 1997-2012 Christopher A. Sims and Tao Zha |
| 19 |
% |
| 20 |
% This free software: you can redistribute it and/or modify |
| 21 |
% it under the terms of the GNU General Public License as published by |
| 22 |
% the Free Software Foundation, either version 3 of the License, or |
| 23 |
% (at your option) any later version. |
| 24 |
% |
| 25 |
% It is distributed in the hope that it will be useful, |
| 26 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 |
% GNU General Public License for more details. |
| 29 |
% |
| 30 |
% If you did not received a copy of the GNU General Public License |
| 31 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 32 |
% |
| 33 |
|
| 34 |
[p,nx]=size(x); |
| 35 |
z = C\(x-xm); |
| 36 |
|
| 37 |
if constIx |
| 38 |
dSh=sum(log(diag(C))); % (detSigma)^(1/2) |
| 39 |
y = exp(-dSh-sum(z.*z,1)/2) / ((2*pi)^(p/2)); |
| 40 |
y = y'; |
| 41 |
else |
| 42 |
y = exp(-sum(z.*z,1)/2); |
| 43 |
y = y'; |
| 44 |
end |