[R] solve vs. qr.solve

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 1 16:39:12 CEST 2000


> Date: Mon, 1 May 2000 16:25:11 +0200 (CEST)
> From: gb <gb at stat.umu.se>
> 
> 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?

Try listing the functions: they are identical.  solve.qr takes the
QR decomposition of A, solves Ax=b as QAx = Rx = Qb (or possibly Q' here).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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