Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Mahalanobis Distance Calculation
Date: Sun, 14 Sep 2008 19:38:01 +0000 (UTC)
Organization: Middle East Technical University
Lines: 30
Message-ID: <gajp6p$9eb$1@fred.mathworks.com>
References: <g999ca$lao$1@fred.mathworks.com> <g9jubp$pkv$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1221421081 9675 172.30.248.37 (14 Sep 2008 19:38:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 14 Sep 2008 19:38:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1506271
Xref: news.mathworks.com comp.soft-sys.matlab:490193



Hi,

as a second question, is multicollinearity prevented by using QR decomposition in mahal function? I knew it works, but using my data set, mahal function did not solve with mahal function and gave an error as "the matrix is singular"
since there is multicollinearity (since correlation matrix includes 1s)
thanks,

dilber ayhan

Peter Perkins <Peteal.PerkinsRemoveThis@mathworks.com> wrote in message <g9jubp$pkv$1@fred.mathworks.com>...
> Baris Yenidunya wrote:
> > Hi,
> > 
> > I'm trying to understand how mahal function in MATLAB works.
> > I see that the method used is different than the MD
> > calculations in the literature. How is QR decomposition used
> > here? Any help (maybe references, links etc.) will be
> > appreciated.
> 
> Baris, presumably by "in the literature", you mean formulas like the one that appears in the help for MAHAL.  That's fine for understanding what the Mahalanobis distance is, but not so good for computational purposes.  MAHAL rewrites that explicit inversion of the cov matrix as a solution of a linear system, by noticing that the (squared) Mahalanobis distance can be expressed as
> 
> D = Y0*S^(-1)*Y0'
>   = Y0*(X0'*X0)^(-1)*Y0'
>   = Y0*((Q*R)'*(Q*R))^(-1)*Y0'
>   = Y0*(R'*R)^(-1)*Y0'
>   = Y0*R^(-1) * (Y0*R^(-1))'
> 
> and then noticing that you can do that using MATLAB's backslash operator.
> 
> Hope this helps.