Fast (Weighted) Linear Model Fitting
flm
is a fast linear model command that takes matrices as input and (by default) only returns a coefficient matrix. 6 different efficient fitting methods are implemented: 4 using base R linear algebra, and 2 utilizing the RcppArmadillo and RcppEigen packages. The function itself only has an overhead of 5-10 microseconds, and is thus well suited as a bootstrap workhorse.
flm(y, X, w = NULL, add.icpt = FALSE, return.raw = FALSE, method = c("lm", "solve", "qr", "arma", "chol", "eigen"), eigen.method = 3L, ...)
y |
a response vector or matrix. Multiple dependent variables are only supported by methods "lm", "solve", "qr" and "chol". |
X |
a matrix of regressors. |
w |
a weight vector. |
add.icpt |
logical. |
return.raw |
logical. |
||||||||||||||||||||||||||||||||||||
method |
an integer or character string specifying the method of computation:
|
||||||||||||||||||||||||||||||||||||
eigen.method |
integer. Select the method of computation used by
See |
||||||||||||||||||||||||||||||||||||
... |
further arguments passed to other methods. Sensible choices are |
If return.raw = FALSE
, a matrix of coefficients with the rows corresponding to the columns of X
, otherwise the raw results from the various methods are returned.
Method "qr" supports sparse matrices, so for an X
matrix with many dummy variables consider method "qr" passing as(X, "dgCMatrix")
instead of just X
.
coef <- flm(mtcars$mpg, qM(mtcars[c("hp","carb")]), mtcars$wt, add.icpt = TRUE) coef lmcoef <- coef(lm(mpg ~ hp + carb, weights = wt, mtcars)) lmcoef all.equal(drop(coef), lmcoef) all_obj_equal(lapply(1:6, function(i) flm(mtcars$mpg, qM(mtcars[c("hp","carb")]), mtcars$wt, add.icpt = TRUE, method = i)))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.