views:

193

answers:

1

R has a qr() function, which performs QR decomposition using either LINPACK or LAPACK (in my experience, the latter is 5% faster). The main object returned is a matrix "qr" that contains in the upper triangular matrix R (i.e. R=qr[upper.tri(qr)]). So far so good. The lower triangular part of qr contains Q "in compact form". One can extract Q from the qr decomposition by using qr.Q(). I would like to find the inverse of qr.Q(). In other word, I do have Q and R, and would like to put them in a "qr" object. R is trivial but Q is not. The goal is to apply to it qr.solve(), which is much faster than solve() on large systems.

A: 

I am confused regarding the qr.Q() code. I tried it and it doesn't seem to work. I'm sure I made a mistake. Could you elaborate on this point of code?

I will say one thing that solve() also depends / uses LAPACK along with almost all the general linear algebra stuff in R. So it should be very fast for large systems as well. You can try to compile R from source with the latest ATLAS libraries. If you have a multicore computer you can use multithreaded ATLAS BLAS & LAPACK, which is extremely fast, comparable to the commercial MKL BLAS & LAPACK from Intel. ATLAS is open source. Using multithreaded ATLAS on a centrino duo Ubuntu 64-bit laptop, I could matrix multiply a 3000 by 3000 matrix of doubles with itself in around 4 seconds. I think all serious R users should take advantage of multithreaded ATLAS. Imho solve() should not be that slow especially if you are taking advantage of all available threads.

Please do elaborate on qr.Q(). Thanks.

Hamaad Shah
I don't think you can do this. I took a look at the qr.solve code and as I see it I think it will take a QR decomp of Q and then return the inverse. I don't think that's what we want and there really doesn't seem to be another way around this. qr.solve will take a matrix, check whether it is a qr object, if not it will take a qr decomp of the matrix and then proceed forward. Turning Q into a qr object and then using the qr.solve method can not be done. At least in my opinion. I could very well be wrong. However as I said before solve() is fast if you use multithreaded ATLAS.
Hamaad Shah