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

On Mon, Aug 10, 2009 at 2:53 PM, Ted Harding
<ted.hard...@manchester.ac.uk>wrote:

>  On 10-Aug-09 21:31:30, cindy Guo wrote:
> > Hi, All,
> > If I  have a symmetric matrix, how can I get the negative square root
> > of the matrx, ie. X^(-1/2) ?
> >
> > Thanks,
> >
> > Cindy
>
>  X <- matrix(c(2,1,1,2),nrow=2)
>  X
> #      [,1] [,2]
> # [1,]    2    1
> # [2,]    1    2
>
>  E <- eigen(X)
>  V <- E$values
>  Q <- E$vectors
>  Y <- Q%*%diag(1/sqrt(V))%*%t(Q)
>  Y
> #            [,1]       [,2]
> # [1,]  0.7886751 -0.2113249
> # [2,] -0.2113249  0.7886751
>
>  solve(Y%*%Y)    ## i.e. find its inverse
> #      [,1] [,2]
> # [1,]    2    1
> # [2,]    1    2
>
> Hence (Y%*%Y)^(-1) = X, or Y = X^(-1/2)
>
> Hopingb this helps,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <ted.hard...@manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 10-Aug-09                                       Time: 22:53:25
> ------------------------------ XFMail ------------------------------
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to