Path: news.mathworks.com!not-for-mail
From: "Kevin Murphy" <murphyk@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: multivariate student t distribution pdf in matlab?
Date: Wed, 4 Nov 2009 19:21:04 +0000 (UTC)
Organization: University of British Columbia
Lines: 44
Message-ID: <hcsk70$86$1@fred.mathworks.com>
References: <0476146b-ad1c-42c3-8990-b31fd9a0953f@m4g2000vbp.googlegroups.com> <go15c6$8m7$1@fred.mathworks.com> <ac6f9610-755e-4753-9f06-9cde1dea082d@v39g2000yqm.googlegroups.com> <go8tt0$rma$1@fred.mathworks.com>
Reply-To: "Kevin Murphy" <murphyk@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257362464 262 172.30.248.38 (4 Nov 2009 19:21:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 19:21:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 330374
Xref: news.mathworks.com comp.soft-sys.matlab:582495



You can just write your own function to compute it - see below.
Note that the mvtpdf function in the stats toolbox
first converts Sigma to a correlation matrix, 
which is nonstandard (as far as I know).
Thus these two methods only
give the same results if Sigma has 1 on all the diagonals.

HTH
Kevin

function logp = mvtLogpdf(X, mu, Sigma, nu)
% Multivariate student T distribution, log pdf
% X(i,:) is i'th case
[N d] = size(X);
M = repmat(mu(:)', N, 1); % replicate the mean across rows
X = X-M;
mahal = sum((X*inv(Sigma)).*X,2); %#ok
logc = gammaln(nu/2 + d/2) - gammaln(nu/2) - 0.5*logdet(Sigma) ...
   - (d/2)*log(nu) - (d/2)*log(pi);
logp = logc  -(nu+d)/2*log1p(mahal/nu);

if 0
   % this check only works if Sigma is a correlation matrix
  logp2 = log(mvtpdf(X, Sigma, nu));
  assert(approxeq(logp, logp2))
end




Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com> wrote in message <go8tt0$rma$1@fred.mathworks.com>...
> per wrote:
> 
> > can you please say more about the transformation? i'm not sure i am
> > following. what kind of transformation of the data would make it so i
> > don't have to give the location (mu) parameter, but just the
> > covariance matrix/correlation matrix (parameter C)?
> 
> No transformation will do that; you will always have to specify the degrees of freedom parameter as well.
> 
> All you need to do to use MVT as a location/scale family is, separately for each column of your data, subtract the corresponding mean and divide by the corresponding scale factor.  It sounds like you have the Statistics Toolbox.  Take a look in stats/private/addtls.m; that code the handles the univariate t-location-scale distribution for the Distribution Fitting Tool is in there.  Look at tlspdf and tlscdf.  You need to do the same thing coordinate-wise.
> 
> Hope this helps.