[R] solve vs. qr.solve

gb gb at stat.umu.se
Mon May 1 16:25:11 CEST 2000


On 1 May 2000, Douglas Bates wrote:
> gb <gb at stat.umu.se> writes:
> 
> > How about 'Ainv <- qr.solve(A)'?
> > 
> > I happened to read the help page for 'qr.solve' the other day, and there I
> > found that qr.solve(A, b) "is == but much better than solve(A) %*% b".
> > (I guess that 'better than' refers to numerical stability?)

> The "better than" refers to the fact that creating the inverse is
> more-or-less equivalent to solving n systems of linear equations,
> where n is the number of columns in A.  If n is large it does not make
> sense to compute the solutions to n systems of equations in order to
> evaluate the solution to one system of equations.

I see! But then I think the help page is somewhat misleading. If it said
'...better than qr.solve(A) %*% b', there would be no doubt.  

> 
> > Is qr.solve generally to be preferred to solve, which seems to be
> > indicated by the cited help page? And what is hidden behind solve?
> 
> I think if you check the code for solve you will find that it usually
> calls qr.solve.  qr.solve is just one method of solving a linear
> system of equations.

I tried

> solve
function(a, b, ...) UseMethod("solve")
> methods(solve)
[1] "solve.default" "solve.qr"     

I guess that I have to find the underlying  C  code to find out
what "solve.default" is, and when which method is used. I have
looked around in R-1.0.1/src/* with no great success. Can I
get a hint where to search?

Thanks, Göran

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list