3

I recently read about how the R matrix of QR decomposition can be calculated using the Choleski decomposition. The relation is:

R = Choleski-decomposition(A^TA)

Example:

> A=matrix(c(1,2,3,2,3,5,1,3,2), nrow=3)
> A
     [,1] [,2] [,3]
[1,]    1    2    1
[2,]    2    3    3
[3,]    3    5    2

> AtA = t(A)%*%A
> AtA
     [,1] [,2] [,3]
[1,]   14   23   13
[2,]   23   38   21
[3,]   13   21   14

Now calculating QR and Choleski decomposition:

> chol(AtA)
         [,1]     [,2]       [,3]
[1,] 3.741657 6.147009  3.4743961
[2,] 0.000000 0.462910 -0.7715167
[3,] 0.000000 0.000000  1.1547005

> qr_A = qr(A)
> qr.R(qr_A)
          [,1]      [,2]       [,3]
[1,] -3.741657 -6.147009 -3.4743961
[2,]  0.000000  0.462910 -0.7715167
[3,]  0.000000  0.000000 -1.1547005

As observed, the values of the R matrix calculated from Choleski and QR decomposition are not the same. The first and the third rows of chol(AtA) are negated w.r.t qr.R(qr_A). Why is that? Is the relation I'm assuming not correct?

1 Answer 1

5

The QR-decomposition of a matrix is not unique! There is a QR-decomposition with R=chol(AtA), but there are also others and qr does not necessairily give that one. In your example

qr.Q(qr_A)%*%qr.R(qr_A) 

and

(qr.Q(qr_A)%*%diag(c(-1,1,-1)))%*%chol(AtA)

are both valid QR-decompositions of A.

3
  • 2
    Exactly. And for some more details, see this excellent answer, given when the exact same question was posed over on the Computational Science SO beta. Commented Oct 23, 2013 at 11:29
  • Great. Thanks! Are there QR decomposition implementations in R that will definitely give me a positive diagonal? Commented Oct 23, 2013 at 14:52
  • 2
    @PrateekKulkarni -- As discussed here, the R package biglm seems to use an implementation that does what you're asking for. Commented Oct 23, 2013 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.