[R] how do I make a correlation matrix positive definite?
Jeremy Miles
jeremy.miles at gmail.com
Fri Oct 22 01:22:41 CEST 2010
Let me rephrase the answer. :)
Correlation matrices are a kind of covariance matrix, where all of the
variances are equal to 1.00.
>From what I understand of make.positive.definite() [which is very
little], it (effectively) treats the matrix as a covariance matrix,
and finds a matrix which is positive definite. This now comprises a
covariance matrix where the variances are not 1.00. Imagine you had
some data which generated that covariance matrix. You could calculate
the correlations - that's exactly what you do, by standardizing the
data, or more easily by standardizing the matrix, which turns it from
a (positive definite) covariance matrix to the equivalent (positive
definite) correlation matrix.
Maybe I've misunderstood, but this seems to be what you're after. If
not, can you explain what you are after (or perhaps wait for another
answer, from someone who has not misunderstood. :)
Jeremy
On 21 October 2010 16:14, HAKAN DEMIRTAS <demirtas at uic.edu> wrote:
>
> I know.
>
> Let me re-phrase the question: How do I convert a non-positive definite
> correlation matrix to a positive-definite correlation matrix in R? I don't
> think cov2cor is relevant here.
>
> Example:
>
>> print(corr.mat)
>
> [,1] [,2] [,3] [,4]
> [1,] 1.00 -0.95 -0.28 -0.64
> [2,] -0.95 1.00 -0.81 -0.38
> [3,] -0.28 -0.81 1.00 -0.11
> [4,] -0.64 -0.38 -0.11 1.00
>>
>> is.positive.definite(corr.mat)
>
> [1] FALSE
>>
>> make.positive.definite(corr.mat)
>
> [,1] [,2] [,3] [,4]
> [1,] 1.2105898 -0.7221551 -0.1246443 -0.4971036
> [2,] -0.7221551 1.2465138 -0.6419150 -0.2253951
> [3,] -0.1246443 -0.6419150 1.1146085 -0.0045829
> [4,] -0.4971036 -0.2253951 -0.0045829 1.0969628
>
>
>
> ----- Original Message -----
> You could use cov2cor() to convert from covariance matrix to
> correlation matrix. If the correlation is >1, the matrix won't be
> positive definite, so you can restandardize the matrix to get a pos
> def correlation matrix.
>
> Jeremy
>
>
> On 21 October 2010 15:50, 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.
>>
>> Hakan Demirtas
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jeremy Miles
> Psychology Research Methods Wiki: www.researchmethodsinpsychology.com
>
>
>
--
Jeremy Miles
Psychology Research Methods Wiki: www.researchmethodsinpsychology.com
More information about the R-help
mailing list