[R] about the Choleski factorization

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Mar 27 19:07:28 CET 2009


Duncan Murdoch wrote:
> On 3/27/2009 11:46 AM, 93354504 wrote:
>> Hi there,
>> Given a positive definite symmetric matrix, I can use chol(x) to 
>> obtain U where U is upper triangular
>> and x=U'U. For example,
>>
>> x=matrix(c(5,1,2,1,3,1,2,1,4),3,3)
>> U=chol(x)
>> U
>> #         [,1]      [,2]      [,3]
>> #[1,] 2.236068 0.4472136 0.8944272
>> #[2,] 0.000000 1.6733201 0.3585686
>> #[3,] 0.000000 0.0000000 1.7525492
>> t(U)%*%U   # this is exactly x
>>
>> Does anyone know how to obtain L such that L is lower triangular and 
>> x=L'L? Thank you.
>>
>> Alex
>>
>> ______________________________________________
>> 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.
> 
>  > rev <- matrix(c(0,0,1,0,1,0,1,0,0),3,3)
>  > rev
>      [,1] [,2] [,3]
> [1,]    0    0    1
> [2,]    0    1    0
> [3,]    1    0    0
> 
> (the matrix that reverses the row and column order when you pre and post 
> multiply it).
> 
> Then
> 
> L <- rev %*% chol(rev %*% x %*% rev) %*% rev
> 
> is what you want, i.e. you reverse the row and column order of the 
> Choleski square root of the reversed x:
> 
>  > x
>      [,1] [,2] [,3]
> [1,]    5    1    2
> [2,]    1    3    1
> [3,]    2    1    4
> 
>  > L <- rev %*% chol(rev %*% x %*% rev) %*% rev
>  > L
>           [,1]     [,2] [,3]
> [1,] 1.9771421 0.000000    0
> [2,] 0.3015113 1.658312    0
> [3,] 1.0000000 0.500000    2

Or just

 > r<-3:1
 > chol(x[r,r])[r,r]
           [,1]     [,2] [,3]
[1,] 1.9771421 0.000000    0
[2,] 0.3015113 1.658312    0
[3,] 1.0000000 0.500000    2

(It is after all, just a matter of starting from the other end).


-- 
    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




More information about the R-help mailing list