[Rcpp-devel] [rcpp-devel] Rcpp Gallery Example fastLm vs R native lm
Thanks. Should have noticed this myself. Dale Smith, Ph.D. Senior Financial Quantitative Analyst Risk & Compliance Fiserv Office: 678-375-5315 www.fiserv.com -----Original Message----- From: Hadley Wickham [mailto:h.wickham at gmail.com] Sent: Thursday, March 21, 2013 11:55 AM To: Smith, Dale Cc: rcpp-devel at lists.r-forge.r-project.org Subject: Re: [Rcpp-devel] [rcpp-devel] Rcpp Gallery Example fastLm vs R native lm
On Thu, Mar 21, 2013 at 10:44 AM, Smith, Dale <Dale.Smith at fiserv.com> wrote:
I have a question about the fastLm example in the Gallery http://gallery.rcpp.org/articles/fast-linear-model-with-armadillo/. I put the code directly into my package (after renaming it fastLmProto so I don't mask the RcppArmadillo function by the same name). After building the package, I wanted to compare results:
require(datasets)
coef(lm(y1 ~ x1, data = anscombe))
(Intercept) x1 3.0000909 0.5000909
coef(fastLmProto(anscombe$y1, as.matrix(anscombe$x1)))
[,1]
[1,] 0.7968032
coef(fastLm(anscombe$y1, as.matrix(anscombe$x1)))
[1] 1.208169 Should I expect the results to match? Why do fastLmProto and fastLm produce a single fitted parameter (I would expect two)? Why are they different? Am I doing something wrong here, or just being na?ve in my assumptions?
Hint:
coef(lm(y1 ~ x1 - 1, data = anscombe))
x1 0.7968032 Hadley -- Chief Scientist, RStudio http://had.co.nz/