| Type: | Package |
| Title: | 'Rcpp' Integration for the 'Eigen' Templated Linear AlgebraLibrary |
| Version: | 0.3.4.0.2 |
| Date: | 2024-08-23 |
| Copyright: | See the file COPYRIGHTS for various Eigen copyright details |
| Description: | R and 'Eigen' integration using 'Rcpp'. 'Eigen' is a C++ template library for linear algebra: matrices, vectors, numerical solvers and related algorithms. It supports dense and sparse matrices on integer, floating point and complex numbers, decompositions of such matrices, and solutions of linear systems. Its performance on many algorithms is comparable with some of the best implementations based on 'Lapack' and level-3 'BLAS'. The 'RcppEigen' package includes the header files from the 'Eigen' C++ template library. Thus users do not need to install 'Eigen' itself in order to use 'RcppEigen'. Since version 3.1.1, 'Eigen' is licensed under the Mozilla Public License (version 2); earlier version were licensed under the GNU LGPL version 3 or later. 'RcppEigen' (the 'Rcpp' bindings/bridge to 'Eigen') is licensed under the GNU GPL version 2 or later, as is the rest of 'Rcpp'. |
| License: | GPL-2 |GPL-3 | file LICENSE [expanded from: GPL (≥ 2) | file LICENSE] |
| LazyLoad: | yes |
| Depends: | R (≥ 3.6.0) |
| LinkingTo: | Rcpp |
| Imports: | Rcpp (≥ 0.11.0), stats, utils |
| Suggests: | Matrix, inline, tinytest, pkgKitten, microbenchmark |
| URL: | https://github.com/RcppCore/RcppEigen,https://dirk.eddelbuettel.com/code/rcpp.eigen.html |
| BugReports: | https://github.com/RcppCore/RcppEigen/issues |
| NeedsCompilation: | yes |
| Packaged: | 2024-08-23 18:11:22 UTC; edd |
| Author: | Doug Bates |
| Maintainer: | Dirk Eddelbuettel <edd@debian.org> |
| Repository: | CRAN |
| Date/Publication: | 2024-08-24 06:30:02 UTC |
Rcpp/Eigen bridge
Description
The package eases the use of the Eigen C++ template library for linearalgebra with Rcpp
Details
This package contains the header files for the Eigen C++ templatelibrary. The typical usage is to install this package and list it intheLinkingTo: line in the ‘DESCRIPTION’ file ofother packages. The C++ source code and the R source code in thispackage are for illustration only.
As described at the Eigen project's home page,http://eigen.tuxfamily.org/index.php?title=Main_Page, Eigen is a versatile, fast, reliableand elegant collection of C++ classes for linear algebra.
References
Douglas Bates and Dirk Eddelbuettel (2013). Fast and Elegant NumericalLinear Algebra Using theRcppEigen Package.Journal ofStatistical Software,52(5), 1-24.URL http://www.jstatsoft.org/v52/i05/.
Create a skeleton for a new package that intends to use RcppEigen
Description
RcppEigen.package.skeleton automates the creation of a new source package that intends to use features of RcppEigen.
It is based on thepackage.skeleton functionwhich it executes first.
Usage
RcppEigen.package.skeleton(name = "anRpackage", list = character(), environment = .GlobalEnv, path = ".", force = FALSE, code_files = character(), example_code = TRUE)Arguments
name | |
list | |
environment | |
path | |
force | |
code_files | |
example_code | If TRUE, example C++ code using RcppEigen is added to the package |
Details
In addition topackage.skeleton :
The ‘DESCRIPTION’ file gains a Depends line requesting that the package depends on Rcpp and RcppEigen and a LinkingTo line so that the package finds Rcpp and RcppEigen header files.
The ‘NAMESPACE’ gains auseDynLib directive.
The ‘src’ directory is created if it does not exists and a ‘Makevars’ file is added setting the environment variable‘PKG_LIBS’ to accomodate the necessary flagsto link with the Rcpp library.
If theexample_code argument is set toTRUE, example files ‘rcppeigen_hello_world.h’ and ‘rcppeigen_hello_world.cpp’are also created in the ‘src’. An R file ‘rcppeigen_hello_world.R’ is expanded in the ‘R’ directory, thercppeigen_hello_world functiondefined in this files makes use of the C++ function ‘rcppeigen_hello_world’defined in the C++ file. These files are given as an example and should eventually by removed from the generated package.
Value
Nothing, used for its side effects
References
Read theWriting R Extensions manual for more details.
Once you have created asource package you need to install it:see theR Installation and Administration manual,INSTALL andinstall.packages.
See Also
Examples
## Not run: RcppEigen.package.skeleton("foobar")## End(Not run)Bare-bones linear model fitting function
Description
fastLm estimates the linear model using one of several methodsimplemented using theEigen linear algebra library.
Usage
fastLmPure(X, y, method = 0L)fastLm(X, ...)## Default S3 method:fastLm(X, y, method = 0L, ...)## S3 method for class 'formula'fastLm(formula, data = list(), method = 0L, ...)Arguments
y | the response vector |
X | a model matrix |
formula | an object of class |
data | an optional data frame, list or environment (or objectcoercible by |
method | an integer scalar with value 0 for the column-pivoted QRdecomposition, 1 for the unpivoted QR decomposition, 2 for the LLTCholesky, 3 for the LDLT Cholesky, 4 for the Jacobi singular valuedecomposition (SVD) and 5 for a method based on theeigenvalue-eigenvector decomposition of |
... | not used |
Details
Linear models should be estimated using thelm function. Insome cases,lm.fit may be appropriate.
ThefastLmPure function provides a reference use case of theEigenC++ template library via the wrapper functions in theRcppEigen package.
ThefastLm function provides a more standard implementation ofa linear model fit, offering both a default and a formula interface aswell asprint,summary andpredict methods.
Internally thefastLm function, by default, uses a QRdecomposition with column pivots, which is a rank-revealingdecomposition, so that it can handle rank-deficient caseseffectively. Other methods for determining least squares solutionsare available according to the value of themethod argument.
An example of the type of situation requiring extra care in checkingfor rank deficiency is a two-way layout with missing cells (see theexamples section). These cases require a special pivoting scheme of“pivot only on (apparent) rank deficiency” which is not part ofconventional linear algebra software.
Value
fastLmPure returns a list with several components:
coefficients | a vector of coefficients |
se | a vector of the standard errors of the coefficient estimates |
rank | a scalar denoting the computed rank of the model matrix |
df.residual | a scalar denoting the degrees of freedom in the model |
residuals | the vector of residuals |
s | a numeric scalar - the root mean square for residuals |
fitted.values | the vector of fitted value |
fastLm returns a richer object which also includes thecall argument similar to thelm orrlm functions..
Author(s)
Eigen is described athttp://eigen.tuxfamily.org/index.php?title=Main_Page.RcppEigen is written by Douglas Bates, Dirk Eddelbuettel and Romain Francois.
References
Douglas Bates and Dirk Eddelbuettel (2013). Fast and Elegant NumericalLinear Algebra Using theRcppEigen Package.Journal ofStatistical Software,52(5), 1-24.URL http://www.jstatsoft.org/v52/i05/.
See Also
Examples
data(trees, package="datasets") mm <- cbind(1, log(trees$Girth)) # model matrix y <- log(trees$Volume) # response ## bare-bones direct interface flm <- fastLmPure(mm, y) print(flm) ## standard R interface for formula or data returning object of class fastLm flmmod <- fastLm( log(Volume) ~ log(Girth), data=trees) summary(flmmod) ## case where non-rank-revealing methods break down dd <- data.frame(f1 = gl(4, 6, labels = LETTERS[1:4]), f2 = gl(3, 2, labels = letters[1:3]))[-(7:8), ] xtabs(~ f2 + f1, dd) # one missing cell mm <- model.matrix(~ f1 * f2, dd) kappa(mm) # large, indicating rank deficiency set.seed(1) dd$y <- mm %*% seq_len(ncol(mm)) + rnorm(nrow(mm), sd = 0.1) summary(lm(y ~ f1 * f2, dd)) # detects rank deficiency try(summary(fastLm(y ~ f1 * f2, dd))) # also detects rank deficiency