Movatterモバイル変換


[0]ホーム

URL:


Dirk Eddelbuettel

RcppArmadillo: R andArmadillo via Rcpp

Build StatusLicenseCRANDependenciesDebian packageLast Commit
DownloadsCRAN useBioConductor useStackOverflow

Synopsis

RcppArmadillo provides an interface from R to and fromArmadillo by utilising theRcpp R/C++ interfacelibrary.

What is Armadillo?

Armadillo is a high-quality linearalgebra library for the C++ language, aiming towards a good balancebetween speed and ease of use. It provides high-level syntax andfunctionalitydeliberately similar to Matlab (TM). Seeits website moreinformation about Armadillo.

So give me an example!

Glad you asked. Here is a light-weight and fast implementation oflinear regression:

#include<RcppArmadillo.h>// [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::export]]Rcpp::List fastLm(const arma::mat& X,const arma::colvec& y){int n= X.n_rows, k= X.n_cols; arma::colvec coef= arma::solve(X, y);// fit model y ~ X arma::colvec res= y- X*coef;// residuals// std.errors of coefficientsdouble s2=std::inner_product(res.begin(), res.end(), res.begin(),0.0)/(n- k); arma::colvec std_err= arma::sqrt(s2* arma::diagvec(arma::pinv(arma::trans(X)*X)));return Rcpp::List::create(Rcpp::Named("coefficients")= coef, Rcpp::Named("stderr")= std_err, Rcpp::Named("df.residual")= n- k);}

You canRcpp::sourceCpp()the file above to compile the function. A slightly more involved versionis also included in the packageasthefastLm() function.

Status

The package is under active development with releases toCRAN about once every other month,and widely-used by other CRAN packages as can be seen from theCRAN packagepage. As of September 2019, there are 658 CRAN packages usingRcppArmadillo.

Documentation

The package contains a pdf vignette which is a pre-print of thepaper byEddelbuettel and Sanderson in CSDA (2014), as well as anintroductory vignette for the sparse matrix conversions.

Installation

RcppArmadillo is aCRANpackage, and lives otherwise in its own habitat onGitHub within theRcppCore GitHuborganization.

Run

install.packages("RcppArmadillo")

to install from your nearest CRAN mirror.

Authors

Dirk Eddelbuettel, Romain Francois, Doug Bates and Binxiang Ni

License

GPL (>= 2)

Initially created: Thu Mar 11 11:14:31 CST 2010
Last modified: Sun May 26 10:09:42 CDT 2024


[8]
ページ先頭

©2009-2025 Movatter.jp