lm.fit {stats}  R Documentation 
Fitter Functions for Linear Models
Description
These are the basic computing engines called by lm
used
to fit linear models. These should usually not be used
directly unless by experienced users. .lm.fit()
is a barebones
wrapper to the innermost QRbased C code, on which
glm.fit
and lsfit
are also based, for
even more experienced users.
Usage
lm.fit (x, y, offset = NULL, method = "qr", tol = 1e7,
singular.ok = TRUE, ...)
lm.wfit(x, y, w, offset = NULL, method = "qr", tol = 1e7,
singular.ok = TRUE, ...)
.lm.fit(x, y, tol = 1e7)
Arguments
x 
design matrix of dimension 
y 
vector of observations of length 
w 
vector of weights (length 
offset 
(numeric of length 
method 
currently, only 
tol 
tolerance for the 
singular.ok 
logical. If 
... 
currently disregarded. 
Details
If y
is a matrix, offset
can be a numeric matrix of the
same dimensions, in which case each column is applied to the
corresponding column of y
.
Value
a list
with components (for lm.fit
and lm.wfit
)
coefficients 

residuals 

fitted.values 

effects 

weights 

rank 
integer, giving the rank 
df.residual 
degrees of freedom of residuals 
qr 
the QR decomposition, see 
Fits without any columns or nonzero weights do not have the
effects
and qr
components.
.lm.fit()
returns a subset of the above, the qr
part
unwrapped, plus a logical component pivoted
indicating if the
underlying QR algorithm did pivot.
See Also
lm
which you should use for linear least squares regression,
unless you know better.
Examples
require(utils)
set.seed(129)
n < 7 ; p < 2
X < matrix(rnorm(n * p), n, p) # no intercept!
y < rnorm(n)
w < rnorm(n)^2
str(lmw < lm.wfit(x = X, y = y, w = w))
str(lm. < lm.fit (x = X, y = y))
## fits w/o intercept:
all.equal(unname(coef(lm(y ~ X1))),
unname(coef( lm.fit(X,y))))
all.equal(unname(coef( lm.fit(X,y))),
coef(.lm.fit(X,y)))
if(require("microbenchmark")) {
mb < microbenchmark(lm(y~X1), lm.fit(X,y), .lm.fit(X,y))
print(mb)
boxplot(mb, notch=TRUE)
}