# What's the underlying algorithm used by R's lm?

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.

• 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
Commented Oct 8, 2015 at 4:58
• 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? Commented Oct 8, 2015 at 9: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). Commented Oct 8, 2015 at 12:38