0

I'm trying to understand how the regression coefficients are generated in the lm.fit function. The only place that math could be done is this line.

    143    z <- .Call(C_Cdqrls, x, y, tol, FALSE)

How do I look at the code being called by .Call? Thanks in advance!

  • Have you seen [this link](https://stat.ethz.ch/pipermail/r-devel/2013-April/066445.html)? – Maurits Evers Mar 21 '18 at 00:46
  • 1
    Maybe [this](https://github.com/wch/r-source/blob/trunk/src/library/stats/src/lm.c) – John Coleman Mar 21 '18 at 00:48
  • Looks like it. Thanks guys. – Thomas Vlasak Mar 21 '18 at 00:56
  • Consulting the source suggests that it is a rabbit hole. After dozens of lines of code which would require a deep understanding of R internals to make sense of, the heavy lifting seems to be in the line which starts `F77_CALL(dqrls)` -- so it ultimately seems to be a wrapper for some Fortran 77 code. – John Coleman Mar 21 '18 at 00:56
  • Here is a simpler alternative: [`fastLm()` code](https://github.com/RcppCore/RcppArmadillo/blob/master/src/fastLm.cpp#L26-L40). There are some high-level R functions too that do the formula interface etc pp. But yes, and the end of the day ... it always ends up in some BLAS function to do the projection efficiently. – Dirk Eddelbuettel Mar 21 '18 at 01:58
  • [here](https://github.com/wch/r-source/blob/af7f52f70101960861e5d995d3a4bec010bc89e6/src/appl/dqrls.f#L82) is the Fortran routine (which points further to a modified QR decomposition routine elsewhere in the Fortran code) – Ben Bolker Mar 21 '18 at 02:49

0 Answers0