[R] very fast OLS regression?

Thomas Lumley tlumley at u.washington.edu
Thu Mar 26 08:31:07 CET 2009


On Wed, 25 Mar 2009, Ravi Varadhan wrote:

> Yes, Bert.  Any least-squares solution that forms X'X and then inverts it is 
> not to be recommended.  If X is nearly rank-deficient, then X'X will be more 
>strongly so.  The QR decomposition approach in my byhand.qr() function is 
>reliable and fast.

Forming the matrix of crossproducts and using cholesky decomposition is faster, so it does depend on the intended use.

In a simulation, the OP's situation, you may well know that X is not nearly rank deficient, in which case the speed advantage may be worthwhile.  After all, even if the condition number of X is 10^5 you will still have five or six accurate digits in the result.

If you are writing code that will be used in ways you have no control over, then of course it makes sense to use the more stable QR decomposition.

      -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list