simona.racioppi at libero.it
2009-Nov-23 12:18 UTC
[R] R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
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.dalgaard at biostat.ku.dk >Data: 21-nov-2009 18.56 >A: "Charles C. Berry"<cberry at tajo.ucsd.edu> >Cc: "simona.racioppi at libero.it"<simona.racioppi at libero.it>, <r-help at r-project.org>>Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski withpivoting of matrix fails> >Charles C. Berry wrote: >> On Sat, 21 Nov 2009, simona.racioppi at 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.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 >
Peter Dalgaard
2009-Nov-23 13:09 UTC
[R] R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
simona.racioppi at libero.it wrote:> 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?No. That is theoretically impossible. If A = B'B, then x'Ax = ||Bx||^2 >= 0 for any x, which implies in particular that all eigenvalues of A should be nonnegative.> > Best, > Simon > >> ----Messaggio originale---- >> Da: p.dalgaard at biostat.ku.dk >> Data: 21-nov-2009 18.56 >> A: "Charles C. Berry"<cberry at tajo.ucsd.edu> >> Cc: "simona.racioppi at libero.it"<simona.racioppi at libero.it>, <r-help at 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.racioppi at 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.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 >> > >-- 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.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Reasonably Related Threads
- R: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
- R: RE: R: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
- Pivoting in chol
- Choleski decomposition
- about the Choleski factorization