View source: R/fastLm.R View source: R/RcppExports.R
fastLm | R Documentation |
fastLm
estimates the linear model using the gsl_multifit_linear
function of the GNU GSL
library.
fastLmPure(X, y) fastLm(X, ...) ## Default S3 method: fastLm(X, y, ...) ## S3 method for class 'formula' fastLm(formula, data = list(), ...)
y |
a vector containing the explained variable. |
X |
a model matrix. |
formula |
a symbolic description of the model to be fit. |
data |
an optional data frame containing the variables in the model. |
... |
not used |
Linear models should be estimated using the lm
function. In
some cases, lm.fit
may be appropriate.
The fastLmPure
function provides a reference use case of the GSL
library via the wrapper functions in the RcppGSL package.
The fastLm
function provides a more standard implementation of
a linear model fit, offering both a default and a formula interface as
well as print
, summary
and predict
methods.
Lastly, one must be be careful in timing comparisons of
lm
and friends versus this approach based on GSL
or Armadillo
. The reason that GSL
or Armadillo
can
do something like lm.fit
faster than the functions in
the stats package is because they use the Lapack version
of the QR decomposition while the stats package uses a modified
Linpack version. Hence GSL
and Armadillo
uses level-3 BLAS code
whereas the stats package uses level-1 BLAS. However,
GSL
or Armadillo
will choke on rank-deficient model matrices whereas
the functions from the stats package will handle them properly due to
the modified Linpack code. Statisticians want a pivoting scheme of
“pivot only on (apparent) rank deficiency” and numerical
analysts have no idea why statisticians want this so it is not part of
conventional linear algebra software.
fastLmPure
returns a list with three components:
coefficients |
a vector of coefficients |
stderr |
a vector of the (estimated) standard errors of the coefficient estimates |
df |
a scalar denoting the degrees of freedom in the model |
fastLm
returns a richer object which also includes the
residuals and call similar to the lm
or
rlm
functions..
The GNU GSL library is being written by team of authors with the overall development, design and implementation lead by Brian Gough and Gerard Jungman. RcppGSL is written by Romain Francois and Dirk Eddelbuettel.
GNU GSL project: https://www.gnu.org/software/gsl/
lm
, lm.fit
data(trees, package="datasets") ## bare-bones direct interface flm <- fastLmPure( cbind(1, log(trees$Girth)), log(trees$Volume) ) print(flm) ## standard R interface for formula or data returning object of class fastLm flmmod <- fastLm( log(Volume) ~ log(Girth), data=trees) summary(flmmod)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.