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 tlum...@u.washington.edu University of Washington, Seattle ______________________________________________ R-help@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.