[Rcpp-devel] [rcpp-devel] Rcpp Gallery Example fastLm vs R native lm

Hadley Wickham h.wickham at gmail.com
Thu Mar 21 16:55:11 CET 2013


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/


More information about the Rcpp-devel mailing list