9
$\begingroup$

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.

$\endgroup$
  • 6
    $\begingroup$ 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. $\endgroup$ – whuber Oct 8 '15 at 4:58
  • 3
    $\begingroup$ 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? $\endgroup$ – Glen_b Oct 8 '15 at 9:55
  • $\begingroup$ 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). $\endgroup$ – PavoDive Oct 8 '15 at 12:38
12
$\begingroup$

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

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks Indeed. Could you point me in a direction, so I'll be able to provide support for the claim? Thanks again $\endgroup$ – PavoDive Oct 8 '15 at 4:43
  • 4
    $\begingroup$ 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. $\endgroup$ – Brian Borchers Oct 8 '15 at 4:45
  • 2
    $\begingroup$ @PavoDive stats.stackexchange.com/questions/94496/lm-function-in-r $\endgroup$ – user81847 Oct 8 '15 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.