[R] matrix power
(Ted Harding)
Ted.Harding at manchester.ac.uk
Tue Aug 11 00:58:06 CEST 2009
On 10-Aug-09 22:36:03, cindy Guo wrote:
> Hi, Ted,
> Thanks for the sample code. It is exactly what I want. But can
> I ask another question? The matrix for which I want the negative
> square root is a covariance matrix. I suppose it should be positive
> definite, so I can do 1/sqrt(V) as you wrote. But the covariance
> matrix I got in R using the function cov has a lot of negative
> eigenvalues, like -5.338634e-17, so 1/sqrt(V) generates NA's. Can
> you tell what's the problem here.
>
> Thanks,
> Cindy
Cindy,
If that -5.338634e-17 is typical of the "lot of negative eigenvalues",
then what you are seeing is the result of R's attempt to calculate
zero eigenvalues, but defeated by the inevitable rounding errors.
In other words, your covariance matrix is singular, and the variables
involved are not linearly independent.
The only thing that is guaranteed about a covariance matrix is that
it is positive semi-definite (not positive definite); in other words
all eigenvalues are positive or zero (mathematically).
For example, if Y=X, var(X) = var(Y) = 1, then
cov(X,Y) = 1 1
1 1
which is singular (eigenvalues = 2, 0).
The result of attempting to compute them is subject to rounding errors,
which (for zero eigenvalues) can be slightly negative.
So the covariance matrix in your case would not have an inverse,
still less a negative square root!
The basic problem is that you have luinear dependence between the
variables. To make progress, you would need to find a maximal linearly
independent set (or possibly find the principal components with
nozero weights).
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 10-Aug-09 Time: 23:58:00
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list