[R] how do I make a correlation matrix positive definite?
Peter Langfelder
peter.langfelder at gmail.com
Fri Oct 22 02:03:02 CEST 2010
On Thu, Oct 21, 2010 at 3:50 PM, HAKAN DEMIRTAS <demirtas at uic.edu> wrote:
> Hi,
>
> If a matrix is not positive definite, make.positive.definite() function in corpcor library finds the nearest positive definite matrix by the method proposed by Higham (1988).
>
> However, when I deal with correlation matrices whose diagonals have to be 1 by definition, how do I do it? The above-mentioned function seem to mess up the diagonal entries. [I haven't seen this complication, but obviously all entries must remain in (-1,1) range after conversion.]
>
> Any R tools to handle this?
>
> I'd appreciate any help.
Well, I can't provide immediate help, but I'm curious where the
correlation matrices are coming from. Autocorrelation matrices (i.e.,
cor(x)) are always positive semi-definite (unless you have missing
data and you specify use = "pairwise.complete.observations", in which
case you may get some negative eigenvalues).
The correlation matrix you provided seems to be inconsistent in the
sense that cor (x[, 1], x[, 2]) is -0.95, cor(x[, 2], x[, 3]) is
-0.81, but cor(x[, 1], x[, 3]) is only -0.25. Using basic geometry
arguments one can show that given the 1,2 and 2,3 correlations, the
1,3 correlation must be at least 0.58. Again, you may get such an
apparently inconsistent correlation matrix if you use
"pairwise.complete.observations" and you have enough missing data.
So one question is whether you do use "pairwise.complete.observations"
when you calculate the matrix. If yes, you may want to try specifying
"complete.observations" which will remove more observations but may
solve your problem.
Peter
More information about the R-help
mailing list