It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible?
Best, Simon >----Messaggio originale---- >Da: p.dalga...@biostat.ku.dk >Data: 21-nov-2009 18.56 >A: "Charles C. Berry"<cbe...@tajo.ucsd.edu> >Cc: "simona.racio...@libero.it"<simona.racio...@libero.it>, <r-h...@r- project.org> >Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails > >Charles C. Berry wrote: >> On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: >> >>> Hi Everyone, >>> >>> I need to take the square root of the following matrix: >>> >>> [,1] [,2] [,3] >>> [1,] 0.5401984 -0.3998675 -1.3785897 >>> [2,] -0.3998675 1.0561872 0.8158639 >>> [3,] -1.3785897 0.8158639 1.6073119 >>> >>> I tried Choleski which fails. I then tried Choleski with pivoting, but >>> unfortunately the square root I get is not valid. I also tried eigen >>> decomposition but i did no get far. >>> >>> Any clue on how to do it?! >> >> >> If you want to take the square root of a negative definite matrix, you >> could use >> >> sqrtm( neg.def.mat ) >> >> from the expm package on rforge: >> >> http://r-forge.r-project.org/projects/expm/ > >But that matrix is not negative definite! It has 2 positive and one >negative eigenvalue. It is non-positive definite. > >It is fairly easy in any case to get a matrix square root from the eigen >decomposition: > > > v%*%diag(sqrt(d+0i))%*%t(v) > [,1] [,2] [,3] >[1,] 0.5164499+0.4152591i -0.1247682-0.0562317i -0.7257079+0.3051868i >[2,] -0.1247682-0.0562317i 0.9618445+0.0076145i 0.3469916-0.0413264i >[3,] -0.7257079+0.3051868i 0.3469916-0.0413264i 1.0513849+0.2242912i > > ch <- v%*%diag(sqrt(d+0i))%*%t(v) > > t(ch)%*% ch > [,1] [,2] [,3] >[1,] 0.5401984+0i -0.3998675-0i -1.3785897-0i >[2,] -0.3998675-0i 1.0561872+0i 0.8158639-0i >[3,] -1.3785897-0i 0.8158639-0i 1.6073119-0i > >A triangular square root is, er, more difficult, but hardly impossible. > >-- > O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 >~~~~~~~~~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 > ______________________________________________ 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.