3# A faster lm() replacement based on Armadillo
5# This improves on the previous version using GNU GSL
7# Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
9# This file is part of Rcpp.
11# Rcpp is free software: you can redistribute it and/or modify it
12# under the terms of the GNU General Public License as published by
13# the Free Software Foundation, either version 2 of the License, or
14# (at your option) any later version.
16# Rcpp is distributed in the hope that it will be useful, but
17# WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
21# You should have received a copy of the GNU General Public License
22# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
24source("lmArmadillo.R")
26checkLmArmadillo <- function(y, X) {
30 rc <- all.equal( as.numeric(res[[1]]), as.numeric(coef(fit))) &
31 all.equal( as.numeric(res[[2]]), as.numeric(coef(summary(fit))[,2]))
35timeLmArmadillo <- function(y, X, N) {
37 meantime <- mean(replicate(N, system.time(fun(y, X))["elapsed"]), trim=0.05)
43X <- cbind( rep(1,n), matrix(rnorm(n*k), ncol=k) )
45y <- as.numeric(X %*% truecoef + rnorm(n))
49stopifnot(checkLmArmadillo(y, X))
50mt <- timeLmArmadillo(y, X, N)
51cat("Armadillo: Running", N, "simulations yields (trimmed) mean time", mt, "\n")