9

I've been asked a question regarding a linear model made with R's lm:

"Did the regression use linear or non-linear iterative least squares?"

I searched a bit and [think that I] understand the difference between the two, but couldn't find any evidence of R's use of linear least squares in lm (which is the one I think it uses).

I combed throuhg lm and its underlying function lm.fit documentation, but couldn't find anything related.

I think the question I was asked is a dumb question, and it's probably wrongly formulated, but I'd appreciate any help as to how I could reply to it.

PavoDive
  • 283
  • 2
  • 10
  • 6
    You could look at the code for `lm` and `lm.fit` by typing their names at the command line. You could also inspect any object returned by `lm` to see the QR decomposition right there. – whuber Oct 08 '15 at 04:58
  • 3
    The question you were asked sounds like they're confused. But anyway, the documentation for `lm` directly tells you it fits linear models, right in the heading it says: "Fitting Linear Models". So linear, not "nonlinear". The documentation for `lm.fit` tells you the algorithm it uses: ... "`.lm.fit()` is bare bone wrapper to the innermost QR-based C code". So it uses QR decomposition to calculate the least squares fit; it mentions the QR decomposition several times later in describing what's returned. What documentation did you read? – Glen_b Oct 08 '15 at 09:55
  • Glen_b, thanks for your clarification. I read the doc files for both functions, I was so fixated on finding something on the lines of "iterative least squares" that I missed the QR bit altogether, and yes, I found the several occurrences of it just _after_ @Brian pointed to it. I agree they're confused and they managed to confuse me (now that I understand better I can steer clear of confusion). – PavoDive Oct 08 '15 at 12:38

1 Answers1

12

lm uses the QR factorization method (a direct rather than iterative method) to solve linear least squares problems.

Brian Borchers
  • 5,015
  • 1
  • 18
  • 27
  • Thanks Indeed. Could you point me in a direction, so I'll be able to provide support for the claim? Thanks again – PavoDive Oct 08 '15 at 04:43
  • 4
    The documentation for lm shows that it solves linear least squares problems and uses QR factorization to do it. There are many textbooks that discuss the use of the QR factorization to solve linear least squares problems- practically any sophomore level introduction to linear algebra text will cover this. – Brian Borchers Oct 08 '15 at 04:45
  • 2
    @PavoDive http://stats.stackexchange.com/questions/94496/lm-function-in-r –  Oct 08 '15 at 06:42